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
Allow 'JsonAnySetter' to flow through JsonCreator. #562
Comments
👍 Is this something that you already considered putting in? |
Considered, yes, had time to try to tackle, no. Would definitely be nice thing to support. |
Any likelihood this will land in 3.x? |
Hi, |
@huhlig It would be nice to get it there, but I can not predict whether it will or not. I do think it would be great to get it to work but there are so many things to work on... I will keep this in mind as one of "more/most wanted" issues. |
I'd also like to see this feature. As a workaround for the immutability enthusiasts, here's an example of using JsonAnySetter in an immutable class (swap out the Map/HashMap for an immutable equivalent as you like). The trick is that the JsonAnySetter method can be made private. @JsonAutoDetect(fieldVisibility = Visibility.ANY, creatorVisibility = Visibility.ANY, setterVisibility = Visibility.ANY)
public static final class WithMap {
@JsonProperty("name")
private String name;
@JsonAnyGetter
private Map<String, String> map;
@JsonCreator
public WithMap(@JsonProperty("name") String name) {
this.name = name;
this.map = new HashMap<>();
}
public WithMap(String name, Map<String, String> map) {
this.name = name;
this.map = map;
}
@JsonAnySetter
private void put(String key, String value) {
map.put(key, value);
}
public String name() {
return name;
}
public Map<String, String> map() {
return Collections.unmodifiableMap(map);
}
} |
@JooHyukKim I think we could use a "failing" test case for this, as pre-cursor to #3439. Note, too, that this is definitely one of Most-Wanted issues open. |
Added a failing test, as a minor help for anyone considering to try to implement. Also, made |
This is great. Thank you for taking care of things in advance. |
Np. Needed that already for reproduction :) |
I could speed up some code if I could write:
The text was updated successfully, but these errors were encountered: