Java record components should dictate written fields#142
Conversation
|
reviewed and am-ed |
|
I am concerned with this PR because we do intentionally enable virtual field so this is a regression side note: think we can upgrade to java 17 as a baseline and avoid asm workaround tip: solution can be to make the tostring/hashcode hardcoded set confgiurable in rg.apache.johnzon.mapper.access.MethodAccessMode#doFindReaders, will work for both mapper and jsonb impl and cover this issue feature edit: created #144 as an alternative which doesn't break current usage, any hope you have a look? |
|
On cell so can check out the reference later. What do we think about a JsonbConfig flag? |
|
But So as far as I interpret it the spec says fields, record components (that's record fields only, not it's methods!) and Java Bean property. A method But That said, Romain is correct to point out that we should have a configuration option to have applications switch back to our old Record handling for some time (maybe even mark it with a deprecation warning?) for compatibility reasons. |
|
@struberg to be honest i'm fine not respecting the spec there and aligning on the POJO side since otherwise it is hard to handle virtual fields and forces to materialize all values which is quite dumb. Also it is our behavior since years (since we do support records) for that exact reason so I would promote it as main behavior, add the toggle as in my PR, and make it to the spec instead of regressing and adding it to the spec later. |
|
What about that option: have that flag, but always enable the spec compliant version (to not serialise Record methods, except if they are annotated with That way we would keep Mapper compatible with the old version by default, and JsonB compatible with the spec by default. |
the feature is used for JSON-B models so it would be a breaking change I don't see much benefit from - and solution to ignore the additional accessors is trivial ( not sure it was obvious but with years the mapper feature was promoted to our JSON-B implementation so I wouldn't assume we can decouple them now. |
|
I've run a few tests with latest yasson (JSON-B reference implementation), and they behave like the JSON-B spec rather clearly defines: results in But results in I don't like this result from the RI neither, as the attribute name is clearly wrong. it should not be getOtherName but only So our old behaviour is clearly a bug and we have to fix it! |
100% disagree on that and on the assumption the RI is right - there are a ton of converter/serializer area we do behave differently so the RI runtime is not a proof. opened jakartaee/jsonb-api#399 |
Given a record like this, only the name and age fields should be written.
https://issues.apache.org/jira/browse/JOHNZON-432