diff --git a/extensions/jackson/deployment/src/main/java/io/quarkus/jackson/deployment/JacksonProcessor.java b/extensions/jackson/deployment/src/main/java/io/quarkus/jackson/deployment/JacksonProcessor.java index dc7b382a921a4..d120cea847a9e 100644 --- a/extensions/jackson/deployment/src/main/java/io/quarkus/jackson/deployment/JacksonProcessor.java +++ b/extensions/jackson/deployment/src/main/java/io/quarkus/jackson/deployment/JacksonProcessor.java @@ -25,6 +25,7 @@ import org.jboss.jandex.Type; import com.fasterxml.jackson.annotation.JsonAutoDetect; +import com.fasterxml.jackson.annotation.JsonSubTypes; import com.fasterxml.jackson.annotation.SimpleObjectIdResolver; import com.fasterxml.jackson.databind.JsonDeserializer; import com.fasterxml.jackson.databind.JsonSerializer; @@ -79,7 +80,7 @@ public class JacksonProcessor { private static final DotName JSON_AUTO_DETECT = DotName.createSimple(JsonAutoDetect.class.getName()); private static final DotName JSON_TYPE_ID_RESOLVER = DotName.createSimple(JsonTypeIdResolver.class.getName()); - + private static final DotName JSON_SUBTYPES = DotName.createSimple(JsonSubTypes.class.getName()); private static final DotName JSON_CREATOR = DotName.createSimple("com.fasterxml.jackson.annotation.JsonCreator"); private static final DotName JSON_NAMING = DotName.createSimple("com.fasterxml.jackson.databind.annotation.JsonNaming"); @@ -98,6 +99,7 @@ public class JacksonProcessor { // this list can probably be enriched with more modules private static final List MODULES_NAMES_TO_AUTO_REGISTER = Arrays.asList(TIME_MODULE, JDK8_MODULE, PARAMETER_NAMES_MODULE); + private static final String[] EMPTY_STRING = new String[0]; @Inject CombinedIndexBuildItem combinedIndexBuildItem; @@ -266,6 +268,25 @@ void register( } } + // register @JsonSubTypes.Type values for reflection + Set subTypeTypesNames = new HashSet<>(); + for (AnnotationInstance subTypeInstance : index.getAnnotations(JSON_SUBTYPES)) { + AnnotationValue subTypeValue = subTypeInstance.value(); + if (subTypeValue != null) { + for (AnnotationInstance subTypeTypeInstance : subTypeValue.asNestedArray()) { + AnnotationValue subTypeTypeValue = subTypeTypeInstance.value(); + if (subTypeTypeValue != null) { + subTypeTypesNames.add(subTypeTypeValue.asClass().name().toString()); + } + } + + } + } + if (!subTypeTypesNames.isEmpty()) { + reflectiveClass.produce(ReflectiveClassBuildItem.builder(subTypeTypesNames.toArray(EMPTY_STRING)) + .methods().fields().build()); + } + // this needs to be registered manually since the runtime module is not indexed by Jandex additionalBeans.produce(new AdditionalBeanBuildItem(ObjectMapperProducer.class)); }