Skip to content

Commit a3f3197

Browse files
committed
Also consider XmlType as triggering the JAXB inclusion
XmlRootElement is optional so we need to trigger the JAXB inclusion with XmlType too.
1 parent a62522d commit a3f3197

File tree

1 file changed

+14
-16
lines changed

1 file changed

+14
-16
lines changed

extensions/jaxb/deployment/src/main/java/io/quarkus/jaxb/deployment/JaxbProcessor.java

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import java.nio.file.Files;
66
import java.nio.file.Path;
77
import java.util.Arrays;
8-
import java.util.Collection;
98
import java.util.List;
109
import java.util.stream.Stream;
1110

@@ -61,6 +60,7 @@
6160
import io.quarkus.deployment.builditem.nativeimage.ServiceProviderBuildItem;
6261

6362
class 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

Comments
 (0)