Skip to content

Commit

Permalink
Fix #2565
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Dec 10, 2019
1 parent 3d1b039 commit 5087767
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 4 deletions.
8 changes: 6 additions & 2 deletions release-notes/CREDITS-2.x
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
2 changes: 2 additions & 0 deletions release-notes/VERSION-2.x
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,12 @@ protected ReferenceTypeSerializer(ReferenceTypeSerializer<?> base, BeanProperty
public JsonSerializer<T> unwrappingSerializer(NameTransformer transformer) {
JsonSerializer<Object> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ static class Issue1256Bean {
// [databind#2303]
static class MyBean2303 {
public AtomicReference<AtomicReference<Integer>> refRef;
}
}

/*
/**********************************************************
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -64,13 +65,19 @@ static class Foo implements Strategy {
}
}

// [databind#2565]: problems with JsonUnwrapped, non-unwrappable type
static class MyBean2565 {
@JsonUnwrapped
public AtomicReference<String> maybeText = new AtomicReference<>("value");
}

/*
/**********************************************************
/* Test methods
/**********************************************************
*/

private final ObjectMapper MAPPER = objectMapper();
private final ObjectMapper MAPPER = newJsonMapper();

public void testAtomicBoolean() throws Exception
{
Expand Down Expand Up @@ -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()));
}
}

0 comments on commit 5087767

Please sign in to comment.