This is an automated email from the ASF dual-hosted git repository. ffang 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 fc97b40 fix camel-quarkus-jacksonxml:JsonView annotations take no effect in n… (#2682) fc97b40 is described below commit fc97b40c922ef9be7831421b94a2a73b0e4547d9 Author: Freeman(Yue) Fang <freeman.f...@gmail.com> AuthorDate: Tue Jun 1 13:58:01 2021 -0400 fix camel-quarkus-jacksonxml:JsonView annotations take no effect in n… (#2682) * fix camel-quarkus-jacksonxml:JsonView annotations take no effect in native mode #2681 * address feedback:using jandex to read JsonView annotations and add class to reflection list #2681 --- .../jacksonxml/deployment/JacksonxmlProcessor.java | 26 ++++++++++++++++++++++ .../jackson/xml/JacksonXmlResource.java | 10 ++++----- 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/extensions/jacksonxml/deployment/src/main/java/org/apache/camel/quarkus/component/jacksonxml/deployment/JacksonxmlProcessor.java b/extensions/jacksonxml/deployment/src/main/java/org/apache/camel/quarkus/component/jacksonxml/deployment/JacksonxmlProcessor.java index fd8594f..23ee72c 100644 --- a/extensions/jacksonxml/deployment/src/main/java/org/apache/camel/quarkus/component/jacksonxml/deployment/JacksonxmlProcessor.java +++ b/extensions/jacksonxml/deployment/src/main/java/org/apache/camel/quarkus/component/jacksonxml/deployment/JacksonxmlProcessor.java @@ -16,8 +16,17 @@ */ package org.apache.camel.quarkus.component.jacksonxml.deployment; +import java.util.function.Function; + +import com.fasterxml.jackson.annotation.JsonView; import io.quarkus.deployment.annotations.BuildStep; +import io.quarkus.deployment.builditem.CombinedIndexBuildItem; import io.quarkus.deployment.builditem.FeatureBuildItem; +import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem; +import org.jboss.jandex.AnnotationValue; +import org.jboss.jandex.DotName; +import org.jboss.jandex.IndexView; +import org.jboss.jandex.Type; class JacksonxmlProcessor { @@ -28,4 +37,21 @@ class JacksonxmlProcessor { return new FeatureBuildItem(FEATURE); } + @BuildStep + ReflectiveClassBuildItem registerJsonView(CombinedIndexBuildItem combinedIndex) { + + IndexView index = combinedIndex.getIndex(); + DotName JSON_VIEW = DotName.createSimple(JsonView.class.getName()); + String[] jsonViews = index.getAnnotations(JSON_VIEW).stream().map(ai -> ai.value()) + .filter(p -> AnnotationValue.Kind.ARRAY.equals(p.kind())) + .map((Function<? super AnnotationValue, ? extends String>) ai -> { + Type[] annotationType = ai.asClassArray(); + return annotationType[0].name().toString(); + }) + .sorted().toArray(String[]::new); + + return new ReflectiveClassBuildItem(false, false, jsonViews); + + } + } diff --git a/integration-tests/dataformats-json/src/main/java/org/apache/camel/quarkus/component/dataformats/jackson/xml/JacksonXmlResource.java b/integration-tests/dataformats-json/src/main/java/org/apache/camel/quarkus/component/dataformats/jackson/xml/JacksonXmlResource.java index 5f2a128..e1506da 100644 --- a/integration-tests/dataformats-json/src/main/java/org/apache/camel/quarkus/component/dataformats/jackson/xml/JacksonXmlResource.java +++ b/integration-tests/dataformats-json/src/main/java/org/apache/camel/quarkus/component/dataformats/jackson/xml/JacksonXmlResource.java @@ -417,8 +417,8 @@ public class JacksonXmlResource { marshalled = producerTemplate.requestBody("direct:jacksonxml-xml-inAgeView", view); marshalledAsString = context.getTypeConverter().convertTo(String.class, marshalled); - /*JsonView doesn't work correctly in native mode, need to investigate more*/ - //assertEquals("<TestPojoView><age>30</age><height>190</height></TestPojoView>", marshalledAsString); + + assertEquals("<TestPojoView><age>30</age><height>190</height></TestPojoView>", marshalledAsString); producerTemplate.sendBody("direct:jacksonxml-xml-backAgeView", marshalled); @@ -483,8 +483,7 @@ public class JacksonXmlResource { Object marshalled = producerTemplate.requestBody("direct:jacksonxml-jsonview-inPojoAgeView", in); String marshalledAsString = context.getTypeConverter().convertTo(String.class, marshalled); - /*JsonView doesn't work correctly in native mode, need to investigate more*/ - //assertEquals("<TestPojoView><age>30</age><height>190</height></TestPojoView>", marshalledAsString); + assertEquals("<TestPojoView><age>30</age><height>190</height></TestPojoView>", marshalledAsString); producerTemplate.sendBody("direct:jacksonxml-jsonview-backPojoAgeView", marshalled); @@ -498,8 +497,7 @@ public class JacksonXmlResource { marshalled = producerTemplate.requestBody("direct:jacksonxml-jsonview-inPojoWeightView", in); marshalledAsString = context.getTypeConverter().convertTo(String.class, marshalled); - /*JsonView doesn't work correctly in native mode, need to investigate more*/ - //assertEquals("<TestPojoView><height>190</height><weight>70</weight></TestPojoView>", marshalledAsString); + assertEquals("<TestPojoView><height>190</height><weight>70</weight></TestPojoView>", marshalledAsString); producerTemplate.sendBody("direct:jacksonxml-jsonview-backPojoWeightView", marshalled);