55import java .nio .file .Files ;
66import java .nio .file .Path ;
77import java .util .Arrays ;
8- import java .util .Collection ;
98import java .util .List ;
109import java .util .stream .Stream ;
1110
6160import io .quarkus .deployment .builditem .nativeimage .ServiceProviderBuildItem ;
6261
6362class JaxbProcessor {
63+
6464 private static final List <Class <?>> JAXB_REFLECTIVE_CLASSES = Arrays .asList (
6565 XmlAccessOrder .class ,
6666 XmlAccessorType .class ,
@@ -107,7 +107,7 @@ class JaxbProcessor {
107107 private static final DotName XML_SCHEMA = DotName .createSimple (XmlSchema .class .getName ());
108108 private static final DotName XML_JAVA_TYPE_ADAPTER = DotName .createSimple (XmlJavaTypeAdapter .class .getName ());
109109
110- private static final List <DotName > REGISTER_TYPE_FOR_REFLECTION_ANNOTATIONS = Arrays .asList (XML_TYPE , XML_REGISTRY );
110+ private static final List <DotName > JAXB_ROOT_ANNOTATIONS = Arrays .asList (XML_ROOT_ELEMENT , XML_TYPE , XML_REGISTRY );
111111
112112 @ Inject
113113 BuildProducer <ReflectiveClassBuildItem > reflectiveClass ;
@@ -128,26 +128,24 @@ void process(BuildProducer<NativeImageSystemPropertyBuildItem> nativeImageProps,
128128
129129 IndexView index = combinedIndexBuildItem .getIndex ();
130130
131- Collection <AnnotationInstance > xmlRootElementInstances = index .getAnnotations (XML_ROOT_ELEMENT );
132- for (AnnotationInstance xmlRootElementInstance : xmlRootElementInstances ) {
133- addReflectiveClass (true , true , xmlRootElementInstance .target ().asClass ().name ().toString ());
134- }
135- if (xmlRootElementInstances .isEmpty () &&
136- fileRoots .isEmpty ()) {
137- return ;
138- }
139-
140131 // Register classes for reflection based on JAXB annotations
141- for (DotName registerTypeAnnotation : REGISTER_TYPE_FOR_REFLECTION_ANNOTATIONS ) {
142- for (AnnotationInstance registerTypeForReflectionAnnotationInstance : index
143- .getAnnotations (registerTypeAnnotation )) {
144- if (registerTypeForReflectionAnnotationInstance .target ().kind () == Kind .CLASS ) {
132+ boolean jaxbRootAnnotationsDetected = false ;
133+
134+ for (DotName jaxbRootAnnotation : JAXB_ROOT_ANNOTATIONS ) {
135+ for (AnnotationInstance jaxbRootAnnotationInstance : index
136+ .getAnnotations (jaxbRootAnnotation )) {
137+ if (jaxbRootAnnotationInstance .target ().kind () == Kind .CLASS ) {
145138 addReflectiveClass (true , true ,
146- registerTypeForReflectionAnnotationInstance .target ().asClass ().name ().toString ());
139+ jaxbRootAnnotationInstance .target ().asClass ().name ().toString ());
140+ jaxbRootAnnotationsDetected = true ;
147141 }
148142 }
149143 }
150144
145+ if (!jaxbRootAnnotationsDetected && fileRoots .isEmpty ()) {
146+ return ;
147+ }
148+
151149 // Register package-infos for reflection
152150 for (AnnotationInstance xmlSchemaInstance : index .getAnnotations (XML_SCHEMA )) {
153151 if (xmlSchemaInstance .target ().kind () == Kind .CLASS ) {
0 commit comments