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 d7e1b79843231..5460754feb9cf 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 @@ -34,6 +34,7 @@ import com.fasterxml.jackson.databind.PropertyNamingStrategies; import com.fasterxml.jackson.databind.PropertyNamingStrategy; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonNaming; import com.fasterxml.jackson.databind.annotation.JsonSerialize; import com.fasterxml.jackson.databind.annotation.JsonTypeIdResolver; import com.fasterxml.jackson.databind.module.SimpleModule; @@ -83,6 +84,7 @@ public class JacksonProcessor { 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 JACKSON_NAMING = DotName.createSimple(JsonNaming.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"); @@ -298,6 +300,18 @@ void register( .methods().fields().build()); } + // register @JsonNaming for reflection + Set namingTypesNames = new HashSet<>(); + for (AnnotationInstance namingInstance : index.getAnnotations(JSON_NAMING)) { + AnnotationValue namingValue = namingInstance.value(); + if (namingValue != null) { + namingTypesNames.add(namingValue.asClass().name().toString()); + } + } + if (!namingTypesNames.isEmpty()) { + reflectiveClass.produce(ReflectiveClassBuildItem.builder(namingTypesNames.toArray(EMPTY_STRING)).build()); + } + // this needs to be registered manually since the runtime module is not indexed by Jandex additionalBeans.produce(new AdditionalBeanBuildItem(ObjectMapperProducer.class)); } diff --git a/integration-tests/jackson/src/main/java/io/quarkus/it/jackson/model/Mammal.java b/integration-tests/jackson/src/main/java/io/quarkus/it/jackson/model/Mammal.java index dc622346349f2..3fd7ff7f5f5ca 100644 --- a/integration-tests/jackson/src/main/java/io/quarkus/it/jackson/model/Mammal.java +++ b/integration-tests/jackson/src/main/java/io/quarkus/it/jackson/model/Mammal.java @@ -5,11 +5,14 @@ import com.fasterxml.jackson.annotation.JsonSubTypes; import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.databind.PropertyNamingStrategies; +import com.fasterxml.jackson.databind.annotation.JsonNaming; @JsonTypeInfo(use = NAME, include = PROPERTY) @JsonSubTypes({ @JsonSubTypes.Type(value = Elephant.class, name = "Elephant"), @JsonSubTypes.Type(value = Whale.class, name = "Whale"), }) +@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class) public interface Mammal { } diff --git a/integration-tests/jackson/src/test/java/io/quarkus/it/jackson/JsonSubTypesResourceTest.java b/integration-tests/jackson/src/test/java/io/quarkus/it/jackson/JsonSubTypesResourceTest.java index fe1979b72db7a..16f25157b5976 100644 --- a/integration-tests/jackson/src/test/java/io/quarkus/it/jackson/JsonSubTypesResourceTest.java +++ b/integration-tests/jackson/src/test/java/io/quarkus/it/jackson/JsonSubTypesResourceTest.java @@ -23,5 +23,6 @@ void test() { .extract().response(); assertThat(response.jsonPath().getString("mammals[0].color")).isEqualTo("white"); assertThat(response.jsonPath().getString("mammals[1].continent")).isEqualTo("africa"); + assertThat(response.jsonPath().getString("mammals[1].horn_length")).isEqualTo("10"); } }