-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Record deserialization bug/breaking change in 2.15 #4105
Comments
Tested with: public class JacksonDatabind4105Test {
@Test
public void test() throws Exception {
ObjectMapper mapper = new ObjectMapper().setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY);
System.out.println("Jackson: " + mapper.version());
record Qwop(String q) {}
final Qwop qwop = new Qwop("");
final String s = mapper.writer().writeValueAsString(qwop);
System.out.println("JSON: " + s);
final Qwop o = mapper.reader().forType(Qwop.class).readValue(s);
System.out.println("Record: " + o);
}
} System.out for
System.out for
Can you provide a more detailed example to demonstrate the issue, please? |
I'm sorry, when I simplified my code for the github issue I inadvertently removed an ObjectMapper configuration that seems to be the culprit:
Setting ALL visibility to NONE and then overriding FIELD to ANY the classic InvalidDefinitionException is thrown: I have now tested the various visibilities and can conclude that in 2.15.x non-annotated records without a default constructor can be deserialized with the configuration:
So it seems like the "breaking" change in 2.15.x is that records are not deserialized with FIELD but with CREATOR + GETTER instead. This is great news, since this is easily configured - but might need documentation to avoid pesky runtime surprises. Leaving this issue open for someone to evaluate if this is the preferred behavior and/or needs documentation. |
I am a bit confounded over the need to make GETTERs visible to be able to deserialize records. This change breaks our class based dto:s. To minimize ceremony we are using the ParameterNamesModule for class deserialization, with a
It seems like the types
|
About the visibility config problem above, there are 2 issues here:
|
Thank you, that is great. |
Thank you @aelgn, @yihtserns for trouble-shooting this. I know Record-handling changes have been frustrating wrt 2.15, but I hope we are in net-positive situation wrt improvements and resolving some (if not all) regressions. |
Search before asking
Describe the bug
In 2.14.x a record could be deserialized without any annotations and dummy default constructor with permissive Field visibility.
Release 2.15.x changed this behavior with I assume #3736
It was very handy to be able to deserialize records without any further ceremony.
As it stands we cannot upgrade to 2.15.x without introducing a lot of boilerplate to our records - or is there a configuration option I have missed?
Version Information
2.15.x
Reproduction
Expected behavior
Expected record deserialization to work with field visibility as in 2.14.x
The text was updated successfully, but these errors were encountered: