From @sguillope on December 5, 2015 15:23
I'm assuming that the following is not expected behaviour. If a field in a JsonUnwrapped object has a matching getter in the outer class, then the field won't get deserialized. In this example id is not deserialized although I'd expect it to be.
Removing the getter getId() from the Outer class fixes the issue.
@Test
public void jsonUnwrappedShouldDeserializeFieldsWithGetterInOuterClass() throws IOException {
final String JSON = "{\"id\": 1, \"name\": \"John\"}";
Outer outer = new ObjectMapper().readValue(JSON, Outer.class);
assertNotNull(outer.getId());
}
static class Outer {
@JsonUnwrapped
private Inner inner;
@JsonIgnore
public Long getId() {
return inner.id;
}
}
static class Inner {
@JsonProperty
Long id;
@JsonProperty
String name;
}
Inspecting the outer object shows:
outer = {Outer@1288}
inner = {Inner@1289}
id = null
name = "John"
Copied from original issue: FasterXML/jackson#38
From @sguillope on December 5, 2015 15:23
I'm assuming that the following is not expected behaviour. If a field in a
JsonUnwrappedobject has a matching getter in the outer class, then the field won't get deserialized. In this exampleidis not deserialized although I'd expect it to be.Removing the getter
getId()from theOuterclass fixes the issue.Inspecting the
outerobject shows:Copied from original issue: FasterXML/jackson#38