diff --git a/src/main/java/com/fasterxml/jackson/databind/introspect/POJOPropertiesCollector.java b/src/main/java/com/fasterxml/jackson/databind/introspect/POJOPropertiesCollector.java index 6a07497c92..449c58ae4b 100644 --- a/src/main/java/com/fasterxml/jackson/databind/introspect/POJOPropertiesCollector.java +++ b/src/main/java/com/fasterxml/jackson/databind/introspect/POJOPropertiesCollector.java @@ -1123,15 +1123,16 @@ protected void _renameProperties(Map props) protected void _renameUsing(Map propMap, PropertyNamingStrategy naming) { + // [databind#4302] since 2.17, Need to skip renaming for Enum properties + if (_type.isEnumType()) { + return; + } + POJOPropertyBuilder[] props = propMap.values().toArray(new POJOPropertyBuilder[propMap.size()]); propMap.clear(); for (POJOPropertyBuilder prop : props) { PropertyName fullName = prop.getFullName(); String rename = null; - // [databind#4302] since 2.17, Need to skip renaming for Enum properties - if (!prop.hasSetter() && prop.getPrimaryType().isEnumType()) { - continue; - } // As per [databind#428] need to skip renaming if property has // explicitly defined name, unless feature is enabled if (!prop.isExplicitlyNamed() || _config.isEnabled(MapperFeature.ALLOW_EXPLICIT_PROPERTY_RENAMING)) { diff --git a/src/test/java/com/fasterxml/jackson/databind/deser/enums/EnumSameName4302Test.java b/src/test/java/com/fasterxml/jackson/databind/deser/enums/EnumSameName4302Test.java index 99ada467d4..1745a9efc5 100644 --- a/src/test/java/com/fasterxml/jackson/databind/deser/enums/EnumSameName4302Test.java +++ b/src/test/java/com/fasterxml/jackson/databind/deser/enums/EnumSameName4302Test.java @@ -7,13 +7,13 @@ import static org.junit.jupiter.api.Assertions.assertEquals; +import static com.fasterxml.jackson.databind.BaseMapTest.a2q; import static com.fasterxml.jackson.databind.BaseMapTest.jsonMapperBuilder; -import static com.fasterxml.jackson.databind.BaseTest.q; +import static com.fasterxml.jackson.databind.BaseMapTest.q; // [databind#4302] public class EnumSameName4302Test { - enum Field4302Enum { FOO(0); @@ -52,12 +52,21 @@ public void setCat(String cat) { } } + static class Field4302Wrapper { + public Field4302Enum wrapped; + + Field4302Wrapper() { } + public Field4302Wrapper(Field4302Enum w) { + wrapped = w; + } + } + private final ObjectMapper MAPPER = jsonMapperBuilder() .propertyNamingStrategy(PropertyNamingStrategies.LOWER_CASE) .build(); @Test - void testShouldWork() throws Exception + void testStandaloneShouldWork() throws Exception { // First, try roundtrip with same-ignore-case name field assertEquals(Field4302Enum.FOO, @@ -78,5 +87,17 @@ void testShouldWork() throws Exception assertEquals(q("CAT"), MAPPER.writeValueAsString(Setter4302Enum.CAT)); } + + @Test + void testWrappedShouldWork() throws Exception + { + // First, try roundtrip with same-ignore-case name field + Field4302Wrapper input = new Field4302Wrapper(Field4302Enum.FOO); + String json = MAPPER.writeValueAsString(input); + assertEquals(a2q("{'wrapped':'FOO'}"), json); + + Field4302Wrapper result = MAPPER.readValue(json, Field4302Wrapper.class); + assertEquals(Field4302Enum.FOO, result.wrapped); + } }