diff --git a/release-notes/CREDITS-2.x b/release-notes/CREDITS-2.x index b65fff8989..8431d7dad3 100644 --- a/release-notes/CREDITS-2.x +++ b/release-notes/CREDITS-2.x @@ -1013,6 +1013,10 @@ Stefan Wendt (stewe@github) * Reported #2560: Check `WRAP_EXCEPTIONS` in `CollectionDeserializer.handleNonArray()` (2.10.2) +Máté Rédecsi (rmatesz@github) + * Reported #953: i-I case convertion problem in Turkish locale with case-insensitive deserialization + (2.11.0) + Ville Koskela (vjkoskela@github) * Contributed #2487: BeanDeserializerBuilder Protected Factory Method for Extension (2.11.0) @@ -1034,6 +1038,6 @@ Joseph Koshakow (jkosh44@github) the same POJO for two different type ids (2.11.0) -Máté Rédecsi (rmatesz@github) - * Reported #953: i-I case convertion problem in Turkish locale with case-insensitive deserialization +Haowei Wen (yushijinhun@github) + * Reported #2565: Java 8 `Optional` not working with `@JsonUnwrapped` on unwrappable type (2.11.0) diff --git a/release-notes/VERSION-2.x b/release-notes/VERSION-2.x index 074726ac47..f49fb8072c 100644 --- a/release-notes/VERSION-2.x +++ b/release-notes/VERSION-2.x @@ -25,6 +25,8 @@ Project: jackson-databind for non-static inner classes #2525: Incorrect `JsonStreamContext` for `TokenBuffer` and `TreeTraversingParser` #2555: Use `@JsonProperty(index)` for sorting properties on serialization +#2565: Java 8 `Optional` not working with `@JsonUnwrapped` on unwrappable type + (reported by Haowei W) - Add `SerializerProvider.findContentValueSerializer()` methods 2.10.2 (not yet released) diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/ReferenceTypeSerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/ReferenceTypeSerializer.java index dc8088c895..54e6bb85d9 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/ReferenceTypeSerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/ReferenceTypeSerializer.java @@ -130,7 +130,12 @@ protected ReferenceTypeSerializer(ReferenceTypeSerializer base, BeanProperty public JsonSerializer unwrappingSerializer(NameTransformer transformer) { JsonSerializer valueSer = _valueSerializer; if (valueSer != null) { + // 09-Dec-2019, tatu: [databind#2565] Can not assume that serializer in + // question actually can unwrap valueSer = valueSer.unwrappingSerializer(transformer); + if (valueSer == _valueSerializer) { + return this; + } } NameTransformer unwrapper = (_unwrapper == null) ? transformer : NameTransformer.chainedTransformer(transformer, _unwrapper); diff --git a/src/test/java/com/fasterxml/jackson/databind/deser/jdk/JDKAtomicTypesDeserTest.java b/src/test/java/com/fasterxml/jackson/databind/deser/jdk/JDKAtomicTypesDeserTest.java index 40b5a45352..62ff2cf2f8 100644 --- a/src/test/java/com/fasterxml/jackson/databind/deser/jdk/JDKAtomicTypesDeserTest.java +++ b/src/test/java/com/fasterxml/jackson/databind/deser/jdk/JDKAtomicTypesDeserTest.java @@ -97,7 +97,7 @@ static class Issue1256Bean { // [databind#2303] static class MyBean2303 { public AtomicReference> refRef; - } + } /* /********************************************************** diff --git a/src/test/java/com/fasterxml/jackson/databind/ser/jdk/AtomicTypeSerializationTest.java b/src/test/java/com/fasterxml/jackson/databind/ser/jdk/AtomicTypeSerializationTest.java index 19f2890189..ff046723d3 100644 --- a/src/test/java/com/fasterxml/jackson/databind/ser/jdk/AtomicTypeSerializationTest.java +++ b/src/test/java/com/fasterxml/jackson/databind/ser/jdk/AtomicTypeSerializationTest.java @@ -5,6 +5,7 @@ import java.util.concurrent.atomic.*; import com.fasterxml.jackson.annotation.*; + import com.fasterxml.jackson.databind.BaseMapTest; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.annotation.JsonSerialize; @@ -64,13 +65,19 @@ static class Foo implements Strategy { } } + // [databind#2565]: problems with JsonUnwrapped, non-unwrappable type + static class MyBean2565 { + @JsonUnwrapped + public AtomicReference maybeText = new AtomicReference<>("value"); + } + /* /********************************************************** /* Test methods /********************************************************** */ - private final ObjectMapper MAPPER = objectMapper(); + private final ObjectMapper MAPPER = newJsonMapper(); public void testAtomicBoolean() throws Exception { @@ -135,4 +142,11 @@ public void testPolymorphicReferenceListOf() throws Exception String json = MAPPER.writeValueAsString(new ContainerB()); assertEquals("{\"strategy\":[" + EXPECTED + "]}", json); } + + // [databind#2565]: problems with JsonUnwrapped, non-unwrappable type + public void testWithUnwrappableUnwrapped() throws Exception + { + assertEquals(aposToQuotes("{'maybeText':'value'}"), + MAPPER.writeValueAsString(new MyBean2565())); + } }