You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by pp...@apache.org on 2021/07/20 11:41:20 UTC
[camel-quarkus] branch main updated: Use of serialization feature
of Quakus (includes Sql and Nitrite) (#2904)
This is an automated email from the ASF dual-hosted git repository.
ppalaga pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git
The following commit(s) were added to refs/heads/main by this push:
new 358d26a Use of serialization feature of Quakus (includes Sql and Nitrite) (#2904)
358d26a is described below
commit 358d26a772959b005161d3c20bc877d7136aa7dc
Author: JiriOndrusek <on...@gmail.com>
AuthorDate: Tue Jul 20 13:41:09 2021 +0200
Use of serialization feature of Quakus (includes Sql and Nitrite) (#2904)
---
.../ROOT/pages/reference/extensions/core.adoc | 8 ++
.../ROOT/pages/reference/extensions/nitrite.adoc | 9 +-
.../ROOT/pages/reference/extensions/sql.adoc | 44 ++-------
.../modules/ROOT/pages/user-guide/native-mode.adoc | 23 +++++
.../deployment/CamelSerializationProcessor.java | 77 ++++++++++++++++
.../spi/CamelSerializationBuildItem.java | 27 ++++++
.../org/apache/camel/quarkus/core/CamelConfig.java | 26 ++++++
.../nitrite/deployment/NitriteProcessor.java | 30 +++++-
extensions/nitrite/runtime/src/main/doc/usage.adoc | 9 +-
.../native-image/serialization-config.json | 41 ---------
.../component/sql/deployment/SqlProcessor.java | 8 ++
.../sql/runtime/src/main/doc/configuration.adoc | 9 ++
extensions/sql/runtime/src/main/doc/usage.adoc | 31 -------
.../apache/camel/quarkus/core/CoreResource.java | 19 ++++
.../camel/quarkus/core/MySerializationObject.java | 102 +++++++++++++++++++++
.../core/src/main/resources/application.properties | 1 +
.../org/apache/camel/quarkus/core/CoreTest.java | 5 +
17 files changed, 347 insertions(+), 122 deletions(-)
diff --git a/docs/modules/ROOT/pages/reference/extensions/core.adoc b/docs/modules/ROOT/pages/reference/extensions/core.adoc
index ba0aeb3..d04c38a 100644
--- a/docs/modules/ROOT/pages/reference/extensions/core.adoc
+++ b/docs/modules/ROOT/pages/reference/extensions/core.adoc
@@ -224,6 +224,14 @@ A comma separated list of Ant-path style patterns to match class names that shou
| `string`
|
+|icon:lock[title=Fixed at build time] [[quarkus.camel.native.reflection.serialization-enabled]]`link:#quarkus.camel.native.reflection.serialization-enabled[quarkus.camel.native.reflection.serialization-enabled]`
+
+If `true`, basic classes are registered for serialization; otherwise basic classes won't be registered automatically for serialization in native mode.
+ List of basic classes: `java.lang.Boolean` `java.lang.Byte` `java.lang.Character` `java.lang.Float` `java.lang.Double` `java.lang.Integer` `java.lang.Long` `java.lang.Number` `java.lang.String` `java.math.BigInteger` `java.util.Date` `java.util.HashMap` `java.util.LinkedHashMap` `org.apache.camel.support.DefaultExchangeHolder`
+ Setting this to `false` helps to reduce the size of the native image. In JVM mode, there is no real benefit of setting this flag to `true` except for making the behavior consistent with native mode.
+| `boolean`
+| `false`
+
|icon:lock[title=Fixed at build time] [[quarkus.camel.csimple.on-build-time-analysis-failure]]`link:#quarkus.camel.csimple.on-build-time-analysis-failure[quarkus.camel.csimple.on-build-time-analysis-failure]`
What to do if it is not possible to extract CSimple expressions from a route definition at build time.
diff --git a/docs/modules/ROOT/pages/reference/extensions/nitrite.adoc b/docs/modules/ROOT/pages/reference/extensions/nitrite.adoc
index e272356..ccdaad3 100644
--- a/docs/modules/ROOT/pages/reference/extensions/nitrite.adoc
+++ b/docs/modules/ROOT/pages/reference/extensions/nitrite.adoc
@@ -41,11 +41,10 @@ Check the xref:user-guide/index.adoc[User guide] for more information about writ
== Usage
-If your persistence objects implement `java.io.Serializable`, you have to add configuration of all serializable classes.
-There is a new serialization support in GraalVM 21.0. Developers can configure classes
-for serialization via the serialization configuration file
-`-H:SerializationConfigurationResources=/path/to-serialization-config.json` option. For more
-information see https://github.com/oracle/graal/pull/2730[PR with feature].
+If your persistence objects in native mode implement `java.io.Serializable` and are not automatically registered for serialization,
+you have to register them for serialization. Look into xref:extensions/core.adoc#serialization_in_native_mode[documentation]
+to see which classes are registered and how to register other ones.
+
If your persistence objects implement `org.dizitart.no2.mapper.Mappable`. All classes have to
implement also `java.io.Serializable` and have to be registered for serialization (see previous option),
diff --git a/docs/modules/ROOT/pages/reference/extensions/sql.adoc b/docs/modules/ROOT/pages/reference/extensions/sql.adoc
index e7e5397..f381427 100644
--- a/docs/modules/ROOT/pages/reference/extensions/sql.adoc
+++ b/docs/modules/ROOT/pages/reference/extensions/sql.adoc
@@ -40,41 +40,6 @@ Or add the coordinates to your existing project:
Check the xref:user-guide/index.adoc[User guide] for more information about writing Camel Quarkus applications.
-== Usage
-
-If you are using SQL Aggregator in native mode, you have to register several classes for serialization using GraalVM
-feature. Serialization support since GraalVM 21.0 allows developers to configure classes for serialization via
-the serialization configuration file `-H:SerializationConfigurationResources=/path-to/serialization-config.json` option.
-For more information see https://github.com/oracle/graal/pull/2730[pull request with feature].
-
-Several classes has to be registered for serialization every time to make SQL Aggregator work in native.
-Here is a template of `serialization-config.json` with all mandatory classes:
-
-```
-[
- {
- "name" : "java.lang.Integer"
- },
- {
- "name" : "java.lang.Number"
- },
- {
- "name" : "java.lang.String"
- },
- {
- "name" : "java.util.HashMap"
- },
- {
- "name" : "java.util.LinkedHashMap"
- },
- {
- "name" : "org.apache.camel.support.DefaultExchangeHolder"
- }
-]
-```
-
-
-
== Additional Camel Quarkus configuration
=== Configuring a DataSource
@@ -102,3 +67,12 @@ Note that URI schemes such as `file` or `http` do not need to be listed.
quarkus.native.resources.includes = queries.sql, sql/*.sql
----
+=== SQL Aggregator ===
+
+If your exchanges in native mode contain objects, which are not automatically registered for serialization (see xref:extensions/core.adoc#serialization_in_native_mode[documentation]),
+you have to register them manually (see xref:extensions/core.adoc#serialization_in_native_mode[documentation])
+
+
+
+
+
diff --git a/docs/modules/ROOT/pages/user-guide/native-mode.adoc b/docs/modules/ROOT/pages/user-guide/native-mode.adoc
index 993b137..8a914d6 100644
--- a/docs/modules/ROOT/pages/user-guide/native-mode.adoc
+++ b/docs/modules/ROOT/pages/user-guide/native-mode.adoc
@@ -111,3 +111,26 @@ in {@code application.properties} - e.g.
quarkus.index-dependency.commons-lang3.group-id = org.apache.commons
quarkus.index-dependency.commons-lang3.artifact-id = commons-lang3
----
+
+[[serialization]]
+== Registration for serialization
+
+If serialization support is requested via `quarkus.camel.native.reflection.serialization-enabled`, following classes are registered for serialization:
+
+* `java.lang.Boolean`
+* `java.lang.Byte`
+* `java.lang.Character`
+* `java.lang.Float`
+* `java.lang.Double`
+* `java.lang.Integer`
+* `java.lang.Long`
+* `java.lang.Number`
+* `java.lang.String`
+* `java.math.BigInteger`
+* `java.util.Date`
+* `java.util.HashMap`
+* `java.util.LinkedHashMap`
+* `org.apache.camel.support.DefaultExchangeHolder`
+
+Users can register more classes using `@RegisterForReflection(serialization = true)`.
+
diff --git a/extensions-core/core/deployment/src/main/java/org/apache/camel/quarkus/core/deployment/CamelSerializationProcessor.java b/extensions-core/core/deployment/src/main/java/org/apache/camel/quarkus/core/deployment/CamelSerializationProcessor.java
new file mode 100644
index 0000000..d183db3
--- /dev/null
+++ b/extensions-core/core/deployment/src/main/java/org/apache/camel/quarkus/core/deployment/CamelSerializationProcessor.java
@@ -0,0 +1,77 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.quarkus.core.deployment;
+
+import java.math.BigInteger;
+import java.util.AbstractMap;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.stream.Stream;
+
+import io.quarkus.deployment.annotations.BuildProducer;
+import io.quarkus.deployment.annotations.BuildStep;
+import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem;
+import org.apache.camel.quarkus.core.CamelConfig;
+import org.apache.camel.quarkus.core.deployment.spi.CamelSerializationBuildItem;
+import org.apache.camel.support.DefaultExchangeHolder;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class CamelSerializationProcessor {
+ private static final Logger LOGGER = LoggerFactory.getLogger(CamelSerializationProcessor.class);
+
+ @BuildStep
+ void produceSerializationBuildItem(CamelConfig config, BuildProducer<CamelSerializationBuildItem> serializationBuildItems) {
+ final CamelConfig.ReflectionConfig reflectionConfig = config.native_.reflection;
+ if (reflectionConfig.serializationEnabled) {
+ LOGGER.debug(
+ "Registration of basic types for serialization is enabled via quarkus.camel.native.reflection.serialization-enabled");
+ serializationBuildItems.produce(new CamelSerializationBuildItem());
+ }
+ }
+
+ @BuildStep
+ void baseSerializationClasses(List<CamelSerializationBuildItem> serializationRequests,
+ BuildProducer<ReflectiveClassBuildItem> reflectiveClasses) {
+
+ if (!serializationRequests.isEmpty()) {
+ String[] classes = Stream.of(Boolean.class,
+ Byte.class,
+ Character.class,
+ Double.class,
+ Float.class,
+ Integer.class,
+ Long.class,
+ Number.class,
+ Date.class,
+ String.class,
+ AbstractMap.class,
+ HashMap.class,
+ LinkedHashMap.class,
+ BigInteger.class,
+ DefaultExchangeHolder.class)
+ .map(c -> c.getName()).toArray(String[]::new);
+
+ //required for serialization of BigInteger
+ reflectiveClasses.produce(new ReflectiveClassBuildItem(false, false, byte[].class));
+
+ reflectiveClasses.produce(ReflectiveClassBuildItem.serializationClass(classes));
+ }
+ }
+}
diff --git a/extensions-core/core/deployment/src/main/java/org/apache/camel/quarkus/core/deployment/spi/CamelSerializationBuildItem.java b/extensions-core/core/deployment/src/main/java/org/apache/camel/quarkus/core/deployment/spi/CamelSerializationBuildItem.java
new file mode 100644
index 0000000..9f3a61b
--- /dev/null
+++ b/extensions-core/core/deployment/src/main/java/org/apache/camel/quarkus/core/deployment/spi/CamelSerializationBuildItem.java
@@ -0,0 +1,27 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.quarkus.core.deployment.spi;
+
+import io.quarkus.builder.item.MultiBuildItem;
+
+/**
+ * Signal that basic classes listed in
+ * {@code org.apache.camel.quarkus.core.deployment.CamelSerializationProcessor.baseSerializationClasses()}
+ * should be registered for serialization.
+ */
+public final class CamelSerializationBuildItem extends MultiBuildItem {
+}
diff --git a/extensions-core/core/runtime/src/main/java/org/apache/camel/quarkus/core/CamelConfig.java b/extensions-core/core/runtime/src/main/java/org/apache/camel/quarkus/core/CamelConfig.java
index 61dc03e..a413fbf 100644
--- a/extensions-core/core/runtime/src/main/java/org/apache/camel/quarkus/core/CamelConfig.java
+++ b/extensions-core/core/runtime/src/main/java/org/apache/camel/quarkus/core/CamelConfig.java
@@ -281,6 +281,32 @@ public class CamelConfig {
@ConfigItem
public Optional<List<String>> includePatterns;
+ /**
+ * If {@code true}, basic classes are registered for serialization; otherwise basic classes won't be registered
+ * automatically for serialization in native mode.
+ * <p>
+ * List of basic classes:
+ * {@code java.lang.Boolean}
+ * {@code java.lang.Byte}
+ * {@code java.lang.Character}
+ * {@code java.lang.Float}
+ * {@code java.lang.Double}
+ * {@code java.lang.Integer}
+ * {@code java.lang.Long}
+ * {@code java.lang.Number}
+ * {@code java.lang.String}
+ * {@code java.math.BigInteger}
+ * {@code java.util.Date}
+ * {@code java.util.HashMap}
+ * {@code java.util.LinkedHashMap}
+ * {@code org.apache.camel.support.DefaultExchangeHolder}
+ *
+ * <p>
+ * Setting this to {@code false} helps to reduce the size of the native image. In JVM mode, there is no real
+ * benefit of setting this flag to {@code true} except for making the behavior consistent with native mode.
+ */
+ @ConfigItem(defaultValue = "false")
+ public boolean serializationEnabled;
}
@ConfigGroup
diff --git a/extensions/nitrite/deployment/src/main/java/org/apache/camel/quarkus/component/nitrite/deployment/NitriteProcessor.java b/extensions/nitrite/deployment/src/main/java/org/apache/camel/quarkus/component/nitrite/deployment/NitriteProcessor.java
index b3f047c..1afdfa7 100644
--- a/extensions/nitrite/deployment/src/main/java/org/apache/camel/quarkus/component/nitrite/deployment/NitriteProcessor.java
+++ b/extensions/nitrite/deployment/src/main/java/org/apache/camel/quarkus/component/nitrite/deployment/NitriteProcessor.java
@@ -16,13 +16,18 @@
*/
package org.apache.camel.quarkus.component.nitrite.deployment;
-import java.util.Arrays;
-import java.util.List;
+import java.util.concurrent.atomic.AtomicBoolean;
+import io.quarkus.deployment.annotations.BuildProducer;
import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.deployment.builditem.FeatureBuildItem;
import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem;
import io.quarkus.deployment.builditem.nativeimage.RuntimeInitializedClassBuildItem;
+import org.apache.camel.quarkus.core.deployment.spi.CamelSerializationBuildItem;
+import org.dizitart.no2.Document;
+import org.dizitart.no2.Index;
+import org.dizitart.no2.NitriteId;
+import org.dizitart.no2.meta.Attributes;
class NitriteProcessor {
@@ -34,14 +39,29 @@ class NitriteProcessor {
}
@BuildStep
+ CamelSerializationBuildItem serialization() {
+ return new CamelSerializationBuildItem();
+ }
+
+ @BuildStep
RuntimeInitializedClassBuildItem runtimeInitializedClass() {
// this class uses a SecureRandom which needs to be initialised at run time
return new RuntimeInitializedClassBuildItem("org.dizitart.no2.Security");
}
@BuildStep
- List<ReflectiveClassBuildItem> reflectiveClasses() {
- return Arrays.asList(new ReflectiveClassBuildItem(false, false, org.h2.store.fs.FilePathNio.class),
- new ReflectiveClassBuildItem(true, false, "sun.reflect.ReflectionFactory"));
+ void reflectiveClasses(BuildProducer<ReflectiveClassBuildItem> reflectiveClasses) {
+ reflectiveClasses.produce(new ReflectiveClassBuildItem(false, false, org.h2.store.fs.FilePathNio.class));
+ reflectiveClasses.produce(new ReflectiveClassBuildItem(true, false, "sun.reflect.ReflectionFactory"));
+
+ String[] dtos = new String[] { NitriteId.class.getName(),
+ Document.class.getName(),
+ Attributes.class.getName(),
+ "org.dizitart.no2.internals.IndexMetaService$IndexMeta",
+ AtomicBoolean.class.getName(),
+ Index.class.getName() };
+
+ reflectiveClasses.produce(ReflectiveClassBuildItem.serializationClass(dtos));
+
}
}
diff --git a/extensions/nitrite/runtime/src/main/doc/usage.adoc b/extensions/nitrite/runtime/src/main/doc/usage.adoc
index 3cadb6f..daddc95 100644
--- a/extensions/nitrite/runtime/src/main/doc/usage.adoc
+++ b/extensions/nitrite/runtime/src/main/doc/usage.adoc
@@ -1,8 +1,7 @@
-If your persistence objects implement `java.io.Serializable`, you have to add configuration of all serializable classes.
-There is a new serialization support in GraalVM 21.0. Developers can configure classes
-for serialization via the serialization configuration file
-`-H:SerializationConfigurationResources=/path/to-serialization-config.json` option. For more
-information see https://github.com/oracle/graal/pull/2730[PR with feature].
+If your persistence objects in native mode implement `java.io.Serializable` and are not automatically registered for serialization,
+you have to register them for serialization. Look into xref:extensions/core.adoc#serialization_in_native_mode[documentation]
+to see which classes are registered and how to register other ones.
+
If your persistence objects implement `org.dizitart.no2.mapper.Mappable`. All classes have to
implement also `java.io.Serializable` and have to be registered for serialization (see previous option),
diff --git a/extensions/nitrite/runtime/src/main/resources/META-INF/native-image/serialization-config.json b/extensions/nitrite/runtime/src/main/resources/META-INF/native-image/serialization-config.json
deleted file mode 100644
index 6557560..0000000
--- a/extensions/nitrite/runtime/src/main/resources/META-INF/native-image/serialization-config.json
+++ /dev/null
@@ -1,41 +0,0 @@
-[
- {
- "name" : "org.dizitart.no2.NitriteId"
- },
- {
- "name" : "java.lang.Long"
- },
- {
- "name" : "java.lang.Number"
- },
- {
- "name" : "org.dizitart.no2.Document"
- },
- {
- "name" : "java.util.LinkedHashMap"
- },
- {
- "name" : "java.util.HashMap"
- },
- {
- "name" : "java.util.Date"
- },
- {
- "name" : "java.lang.String"
- },
- {
- "name" : "java.lang.Integer"
- },
- {
- "name" : "org.dizitart.no2.meta.Attributes"
- },
- {
- "name" : "org.dizitart.no2.internals.IndexMetaService$IndexMeta"
- },
- {
- "name" : "java.util.concurrent.atomic.AtomicBoolean"
- },
- {
- "name" : "org.dizitart.no2.Index"
- }
-]
\ No newline at end of file
diff --git a/extensions/sql/deployment/src/main/java/org/apache/camel/quarkus/component/sql/deployment/SqlProcessor.java b/extensions/sql/deployment/src/main/java/org/apache/camel/quarkus/component/sql/deployment/SqlProcessor.java
index 4dfbd97..c7208b9 100644
--- a/extensions/sql/deployment/src/main/java/org/apache/camel/quarkus/component/sql/deployment/SqlProcessor.java
+++ b/extensions/sql/deployment/src/main/java/org/apache/camel/quarkus/component/sql/deployment/SqlProcessor.java
@@ -17,6 +17,7 @@
package org.apache.camel.quarkus.component.sql.deployment;
import java.sql.Types;
+import java.util.LinkedHashMap;
import io.quarkus.deployment.annotations.BuildProducer;
import io.quarkus.deployment.annotations.BuildStep;
@@ -24,6 +25,7 @@ import io.quarkus.deployment.builditem.FeatureBuildItem;
import io.quarkus.deployment.builditem.nativeimage.NativeImageResourceBuildItem;
import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem;
import org.apache.camel.quarkus.component.sql.CamelSqlConfig;
+import org.apache.camel.quarkus.core.deployment.spi.CamelSerializationBuildItem;
import org.apache.camel.support.DefaultExchangeHolder;
import org.jboss.logging.Logger;
@@ -38,8 +40,14 @@ class SqlProcessor {
}
@BuildStep
+ CamelSerializationBuildItem serialization() {
+ return new CamelSerializationBuildItem();
+ }
+
+ @BuildStep
void registerForReflection(BuildProducer<ReflectiveClassBuildItem> reflectiveClass) {
reflectiveClass.produce(new ReflectiveClassBuildItem(false, true, Types.class, DefaultExchangeHolder.class));
+ reflectiveClass.produce(ReflectiveClassBuildItem.serializationClass(LinkedHashMap.class.getName()));
}
@BuildStep
diff --git a/extensions/sql/runtime/src/main/doc/configuration.adoc b/extensions/sql/runtime/src/main/doc/configuration.adoc
index 6a55bf0..f0af7ad 100644
--- a/extensions/sql/runtime/src/main/doc/configuration.adoc
+++ b/extensions/sql/runtime/src/main/doc/configuration.adoc
@@ -22,3 +22,12 @@ Note that URI schemes such as `file` or `http` do not need to be listed.
----
quarkus.native.resources.includes = queries.sql, sql/*.sql
----
+
+=== SQL Aggregator ===
+
+If your exchanges in native mode contain objects, which are not automatically registered for serialization (see xref:extensions/core.adoc#serialization_in_native_mode[documentation]),
+you have to register them manually (see xref:extensions/core.adoc#serialization_in_native_mode[documentation])
+
+
+
+
diff --git a/extensions/sql/runtime/src/main/doc/usage.adoc b/extensions/sql/runtime/src/main/doc/usage.adoc
deleted file mode 100644
index 29601d1..0000000
--- a/extensions/sql/runtime/src/main/doc/usage.adoc
+++ /dev/null
@@ -1,31 +0,0 @@
-If you are using SQL Aggregator in native mode, you have to register several classes for serialization using GraalVM
-feature. Serialization support since GraalVM 21.0 allows developers to configure classes for serialization via
-the serialization configuration file `-H:SerializationConfigurationResources=/path-to/serialization-config.json` option.
-For more information see https://github.com/oracle/graal/pull/2730[pull request with feature].
-
-Several classes has to be registered for serialization every time to make SQL Aggregator work in native.
-Here is a template of `serialization-config.json` with all mandatory classes:
-
-```
-[
- {
- "name" : "java.lang.Integer"
- },
- {
- "name" : "java.lang.Number"
- },
- {
- "name" : "java.lang.String"
- },
- {
- "name" : "java.util.HashMap"
- },
- {
- "name" : "java.util.LinkedHashMap"
- },
- {
- "name" : "org.apache.camel.support.DefaultExchangeHolder"
- }
-]
-```
-
diff --git a/integration-test-groups/foundation/core/src/main/java/org/apache/camel/quarkus/core/CoreResource.java b/integration-test-groups/foundation/core/src/main/java/org/apache/camel/quarkus/core/CoreResource.java
index e1c131f..c576fd1 100644
--- a/integration-test-groups/foundation/core/src/main/java/org/apache/camel/quarkus/core/CoreResource.java
+++ b/integration-test-groups/foundation/core/src/main/java/org/apache/camel/quarkus/core/CoreResource.java
@@ -16,9 +16,12 @@
*/
package org.apache.camel.quarkus.core;
+import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
@@ -254,4 +257,20 @@ public class CoreResource {
public String customBeanResolvedByType() {
return myPropertiesCustomBeanResolvedByType.toString();
}
+
+ @Path("/serialization")
+ @GET
+ @Produces(MediaType.TEXT_PLAIN)
+ public boolean serialization() throws IOException, ClassNotFoundException {
+ MySerializationObject instance = new MySerializationObject();
+ instance.initValues();
+
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ ObjectOutputStream os = new ObjectOutputStream(out);
+ os.writeObject(instance);
+ ByteArrayInputStream bais = new ByteArrayInputStream(out.toByteArray());
+ ObjectInputStream is = new ObjectInputStream(bais);
+ return ((MySerializationObject) is.readObject()).isCorrect();
+ }
+
}
diff --git a/integration-test-groups/foundation/core/src/main/java/org/apache/camel/quarkus/core/MySerializationObject.java b/integration-test-groups/foundation/core/src/main/java/org/apache/camel/quarkus/core/MySerializationObject.java
new file mode 100644
index 0000000..9e83423
--- /dev/null
+++ b/integration-test-groups/foundation/core/src/main/java/org/apache/camel/quarkus/core/MySerializationObject.java
@@ -0,0 +1,102 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.quarkus.core;
+
+import java.io.Serializable;
+import java.math.BigInteger;
+import java.time.Instant;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+
+import io.quarkus.runtime.annotations.RegisterForReflection;
+
+@RegisterForReflection(serialization = true)
+public class MySerializationObject implements Serializable {
+
+ private Long _long;
+ private Integer _integer;
+ private Date _date;
+ private String _string;
+ private Float _float;
+ private Double _double;
+ private BigInteger _bigInteger;
+ private HashMap _hashMap;
+ private LinkedHashMap _linkedHashMap;
+ private Character _char;
+ private Boolean _boolean;
+ private Byte _byte;
+
+ public void initValues() {
+ _long = 1l;
+ _integer = 1;
+ _date = Date.from(Instant.ofEpochMilli(123456789));
+ _string = "A";
+ _float = Float.valueOf(1);
+ _double = Double.valueOf(1);
+ _bigInteger = BigInteger.valueOf(1);
+ _hashMap = new HashMap();
+ _hashMap.put(1, "one");
+ _linkedHashMap = new LinkedHashMap();
+ _linkedHashMap.put(1, "one");
+ _char = Character.valueOf('a');
+ _boolean = Boolean.FALSE;
+ _byte = Byte.valueOf("1");
+ }
+
+ public boolean isCorrect() {
+ if (_long == null || _long != 1l) {
+ return false;
+ }
+ if (_integer == null || _integer != 1) {
+ return false;
+ }
+ if (_date == null || _date.getTime() != 123456789) {
+ return false;
+ }
+ if (!"A".equals(_string)) {
+ return false;
+ }
+ if (_float == null || _float != 1) {
+ return false;
+ }
+ if (_double == null || _double != 1) {
+ return false;
+ }
+ if (_bigInteger == null || _bigInteger.intValue() != 1) {
+ return false;
+ }
+ if (_hashMap == null || _hashMap.size() != 1 || !"one".equals(_hashMap.get(1))) {
+ return false;
+ }
+ if (_linkedHashMap == null || _linkedHashMap.size() != 1 || !"one".equals(_linkedHashMap.get(1))) {
+ return false;
+ }
+ if (_char == null || _char != 'a') {
+ return false;
+ }
+ if (_boolean == null || _boolean) {
+ return false;
+ }
+ if (_byte == null || !_byte.equals(Byte.valueOf("1"))) {
+ return false;
+ }
+
+ return true;
+ }
+
+}
diff --git a/integration-test-groups/foundation/core/src/main/resources/application.properties b/integration-test-groups/foundation/core/src/main/resources/application.properties
index df8de76..1a377ea 100644
--- a/integration-test-groups/foundation/core/src/main/resources/application.properties
+++ b/integration-test-groups/foundation/core/src/main/resources/application.properties
@@ -29,6 +29,7 @@ quarkus.camel.native.reflection.exclude-patterns = org.apache.commons.lang3.tupl
quarkus.camel.runtime-catalog.languages = false
quarkus.native.resources.includes = mysimple.txt,include-pattern-folder/*
quarkus.native.resources.excludes = exclude-pattern-folder/*,include-pattern-folder/excluded.txt
+quarkus.camel.native.reflection.serialization-enabled = true
#
# Camel
diff --git a/integration-test-groups/foundation/core/src/test/java/org/apache/camel/quarkus/core/CoreTest.java b/integration-test-groups/foundation/core/src/test/java/org/apache/camel/quarkus/core/CoreTest.java
index 21f4f5a..0a223cc 100644
--- a/integration-test-groups/foundation/core/src/test/java/org/apache/camel/quarkus/core/CoreTest.java
+++ b/integration-test-groups/foundation/core/src/test/java/org/apache/camel/quarkus/core/CoreTest.java
@@ -119,4 +119,9 @@ public class CoreTest {
void testCustomBeanResolvedByType() {
RestAssured.when().get("/core/custom-bean-resolved-by-type").then().body(is("Donkey"));
}
+
+ @Test
+ void testSerialization() {
+ RestAssured.when().get("/core/serialization").then().body(is("true"));
+ }
}