Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@JsonAnySetter on field ignoring unrecognized properties if they are declared before the last recognized properties in JSON #4639

Open
1 task done
yihtserns opened this issue Jul 23, 2024 · 0 comments
Labels

Comments

@yihtserns
Copy link
Contributor

yihtserns commented Jul 23, 2024

Search before asking

  • I searched in the issues and found nothing similar.

Describe the bug

Say a bean class only recognize property/field p1, and we have the following JSONs:

{
    "p1": ..., // goes to p1 field
    "p2": ..., // goes to @JsonAnySetter field
    "p3": ... // goes to @JsonAnySetter field
}

{
    "p2": ..., // goes missing ⚠
    "p1": ..., // goes to p1 field
    "p3": ... // goes to @JsonAnySetter field
}


{
    "p2": ..., // goes missing ⚠
    "p3": ..., // goes missing ⚠
    "p1": ... // goes to p1 field
}

Version Information

2.18

Reproduction

public static class Bean {

    private int b;
    private int d;
    @JsonAnySetter
    private Map<String, ?> any;

    @JsonCreator
    public Bean(@JsonProperty("b") int b, @JsonProperty("d") int d) {
        this.b = b;
        this.d = d;
    }
}
...

String json = "{\"a\":1,\"b\":2,\"c\":3,\"d\":4,\"e\":5,\"f\":6}";

Bean bean = new ObjectMapper().readValue(json, Bean.class);
assertEquals(2, bean.b);
assertEquals(4, bean.d);
// failed with:
// org.opentest4j.AssertionFailedError: 
// Expected :{b=2, c=3, e=5, f=6}
// Actual   :{e=5, f=6}
assertEquals(Map.of("a", 1, "c", 3, "e", 5, "f", 6), bean.any);

Expected behavior

No response

Additional context

@yihtserns yihtserns added the to-evaluate Issue that has been received but not yet evaluated label Jul 23, 2024
@cowtowncoder cowtowncoder added 2.18 and removed to-evaluate Issue that has been received but not yet evaluated labels Jul 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants