-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
JsonProperty.Access.READ_ONLY
does not work with "getter-as-setter" Collection
s
#2118
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
Comments
@zhangyangyu I can reproduce the issue, but have to think if and how to fix it. The problem is that by default setting
is You can change this behavior by disabling |
Thanks for reply and explanation. Changing a global config could solve the problem but might not ideal. I hope |
I have the same issue with v2.11.0 Code snippet : public static void main(String[] args) throws Exception {
ObjectMapper mapper = new ObjectMapper()
.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
String json = mapper.writeValueAsString(new Bar());
System.out.println(json);
System.out.println("Deserialized: " + mapper.readValue(json, Bar.class));
}
@JsonInclude(JsonInclude.Include.NON_NULL)
public static abstract class Foo {
@JsonProperty(value = "subfields", access = JsonProperty.Access.READ_ONLY)
protected abstract Set<String> subfields();
}
public static class Bar extends Foo {
@Override
protected Set<String> subfields() {
return Set.of("a", "b");
}
} I get any I managed to fix it by adding the annotation I do not want to disable the |
An simpler way to fix it is to remove the See #2283 |
JsonProperty.Access.READ_ONLY
does not work with "getter-as-setter" Collection
s
@jdussouillez I think you can achieve this by having both setter and getter, and configuring them separately (use Aside from trying to fix this issue (which I hope to achieve at some point; but fix is not trivial unfortunately), another possibility might be to add a setting for |
I think I managed to fix this, although verification would be appreciated: fix in |
I could still encounter the problem that
JsonProperty.Access.READ_ONLY
not work. I have read #1805 , and my jackson.databind version is 2.9.5. I also checked 2.9.6.I have reduced my example as:
I hope
securityGroupRules
won't be deserialized but it still is. If I changeJsonProperty(value="security_group_rules", access=JsonProperty.Access.READ_ONLY)
toJsonIgnoreProperties(value="security_group_rules", allowGetters=true)
as metioned in #1805, it throwsUnrecognizedPropertyException
instead of printing{"security_group_rules":[{"id":"id1"},{"id":"id2"},{"id":"id3"},{"id":"id4"}]}
. I'd like the former behaviour since in project I can setFAIL_ON_UNKNOWN_PROPERTIES
to avoid the error.The text was updated successfully, but these errors were encountered: