Skip to content

@JsonUnwrapped fields with matching @JsonIgnored getter in outer class are ignored #1075

Description

@sguillope

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.2has-failing-testIndicates that there exists a test case (under `failing/`) to reproduce the issue

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions