-
-
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
Serializing a Java 16 Record includes transient data from getters from implemented interfaces #3628
Comments
My first thought is that I would consider this a feature: a getter is a getter, even for Records. If they are not to be serialized, they should be marked to be ignored; either by annotations ( In theory I guess it would be possible to change default visibility level of |
Reading the last comment somehow reminds me of 50dd52f, where you created a custom default It is a possible option to change that |
@cowtowncoder Eh while trying a different mecha than |
Yeah I don't know. Perhaps. That's the challenge of missing test coverage -- functionality not covered by tests can easily break. |
@hjohn can you help provide a code snippet so we can know exactly how your workaround looks like, so we can properly test whether it's broken in |
I just configured a custom
With this setup it only detects the records fields, and since you can't add any fields to a record, that's all the data you would need to store. |
One thing to note is that |
That workaround + 😬 |
Is that a cryptic way of saying that limiting visibility to fields only for records breaks in 2.15.0-rc2 ? |
Yes. Only an empty JSON hash/object will be generated when that workaround is used with UPDATE: The workaround used above is working again in |
This may be by design, but I think it may be a bug...
Describe the bug
When serializing a record that implements an interface, Jackson also serializes any values resulting from getters in an implemented interface. Such additional "getters" should however always be perceived as transient, as they cannot influence the actual data stored in the record.
For example:
The getters here are transient (they contain no new information) and are coming from the
AggregateEvent
interface:Work around
Configuring
setVisibility(PropertyAccessor.GETTER, Visibility.NONE)
will also ignore the records fields (not sure if they should be considered "getters", but I suppose they might). Configuring in additionsetVisibility(PropertyAccessor.FIELD, Visibility.ANY)
resolves the issue.Version information
Which Jackson version(s) was this for? 2.13.4
Expected behavior
I would expect Jackson to recognize records, and recognize that it is fully defined by the records fields; any additional methods, getters or otherwise, should be considered irrelevant for reconstructing the record.
The text was updated successfully, but these errors were encountered: