diff --git a/release-notes/CREDITS-2.x b/release-notes/CREDITS-2.x index 3ee623c65e..a01042f50f 100644 --- a/release-notes/CREDITS-2.x +++ b/release-notes/CREDITS-2.x @@ -1838,6 +1838,13 @@ Maxim Valeev (@MaximValeev) * Reported #4508: Deserialized JsonAnySetter field in Kotlin data class is null (2.18.1) +@SandeepGaur2016 + + * Contributed fix for #2461: Nested `@JsonUnwrapped` property names not correctly handled + (2.19.0) + * Contributed fix for #4697: Inconsistent serialization with `@JsonUnwrapped` annotation + using shared vs. new `ObjectMapper` instances + (2.19.0) Lars Benedetto (@lbenedetto) * Contributed #4676: Support other enum naming strategies than camelCase diff --git a/release-notes/VERSION-2.x b/release-notes/VERSION-2.x index 2207234758..4bdfa527db 100644 --- a/release-notes/VERSION-2.x +++ b/release-notes/VERSION-2.x @@ -6,9 +6,15 @@ Project: jackson-databind 2.19.0 (not yet released) +#2461: Nested `@JsonUnwrapped` property names not correctly handled + (reported by @plovell) + (fix contributed by @SandeepGaur2016) #4676: Support other enum naming strategies than camelCase (requested by @hajdamak) - (contributed by Lars B) + (contributed by Lars +#4697: Inconsistent serialization with `@JsonUnwrapped` annotation + using shared vs. new `ObjectMapper` instances + (fix contributed by @SandeepGaur2016) 2.18.1 (WIP-2024) diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/BeanPropertyWriter.java b/src/main/java/com/fasterxml/jackson/databind/ser/BeanPropertyWriter.java index 812c239032..45ec7a0ba5 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/BeanPropertyWriter.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/BeanPropertyWriter.java @@ -222,8 +222,7 @@ public BeanPropertyWriter(BeanPropertyDefinition propDef, _declaredType = declaredType; _serializer = (JsonSerializer) ser; - _dynamicSerializers = (ser == null) ? PropertySerializerMap - .emptyForProperties() : null; + _dynamicSerializers = (ser == null) ? PropertySerializerMap.emptyForProperties() : null; _typeSerializer = typeSer; _cfgSerializationType = serType; @@ -325,7 +324,7 @@ protected BeanPropertyWriter(BeanPropertyWriter base, PropertyName name) { base._internalSettings); } _cfgSerializationType = base._cfgSerializationType; - _dynamicSerializers = base._dynamicSerializers; + _dynamicSerializers = PropertySerializerMap.emptyForProperties(); _suppressNulls = base._suppressNulls; _suppressableValue = base._suppressableValue; _includeInViews = base._includeInViews; @@ -350,7 +349,7 @@ protected BeanPropertyWriter(BeanPropertyWriter base, SerializedString name) { base._internalSettings); } _cfgSerializationType = base._cfgSerializationType; - _dynamicSerializers = base._dynamicSerializers; + _dynamicSerializers = PropertySerializerMap.emptyForProperties(); _suppressNulls = base._suppressNulls; _suppressableValue = base._suppressableValue; _includeInViews = base._includeInViews; diff --git a/src/test/java/com/fasterxml/jackson/databind/tofix/JsonUnwrappedInconsistentSerialization4697Test.java b/src/test/java/com/fasterxml/jackson/databind/tofix/JsonUnwrappedInconsistentSerialization4697Test.java index f2e6057f64..565487e89d 100644 --- a/src/test/java/com/fasterxml/jackson/databind/tofix/JsonUnwrappedInconsistentSerialization4697Test.java +++ b/src/test/java/com/fasterxml/jackson/databind/tofix/JsonUnwrappedInconsistentSerialization4697Test.java @@ -35,13 +35,16 @@ public Third() { } } + public static class AnotherFirst { + public Third thrid = new Third(); + } + public static class Common { public String a; public String b; public Common() {} } - @JacksonTestFailureExpected @Test public void testInconsistentSer() throws Exception { First first = new First(); @@ -51,8 +54,23 @@ public void testInconsistentSer() throws Exception { ObjectMapper secondMapper = newJsonMapper(); firstMapper.writeValueAsString(first); + firstMapper.writeValueAsString(second); + assertEquals( + firstMapper.writeValueAsString(second), + secondMapper.writeValueAsString(second)); + } + @Test + public void testInconsistentSer1() throws Exception { + AnotherFirst first = new AnotherFirst(); + Second second = new Second(); + + ObjectMapper firstMapper = newJsonMapper(); + ObjectMapper secondMapper = newJsonMapper(); + + firstMapper.writeValueAsString(first); + firstMapper.writeValueAsString(second); assertEquals( firstMapper.writeValueAsString(second), secondMapper.writeValueAsString(second)); } -} +} \ No newline at end of file diff --git a/src/test/java/com/fasterxml/jackson/databind/tofix/UnwrappedCaching2461Test.java b/src/test/java/com/fasterxml/jackson/databind/tofix/UnwrappedCaching2461Test.java index dc3d867be9..2728b3a0dd 100644 --- a/src/test/java/com/fasterxml/jackson/databind/tofix/UnwrappedCaching2461Test.java +++ b/src/test/java/com/fasterxml/jackson/databind/tofix/UnwrappedCaching2461Test.java @@ -39,7 +39,6 @@ static class OuterContainer { } // [databind#2461] - @JacksonTestFailureExpected @Test void unwrappedCaching() throws Exception { final InnerContainer inner = new InnerContainer(new Base("12345"));