Skip to content
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

Fixing records deserialization issues with read-access when json renamed to same property name #5072

Closed
wants to merge 6 commits into from

Conversation

iifawzi
Copy link
Contributor

@iifawzi iifawzi commented Apr 6, 2025

Hello, this is an attempt to resolve deserialization issues when @JsonProperty.value has the same name as the property.

After debugging, I realized that this's the root cause of #5049. Given for records no constructors' parameters, this condition always passes for both attributes because for read-access only, ctorParam is always null due to removeNonVisible logic.
Changing this to ensure we don't get into the replacement if it is null seemed enough to fix the duplicate issue and to also fix the ignorance of the access for records #4628

However, as this seems to be fixing all issues related to records, it's still not fixing the issue with JsonIgnore mentioned #4628. The root cause is this:

if (_replaceCreatorProperty(_creatorProperties, prop)) {
// [databind#2001]: New name of property was ignored previously? Remove from ignored
// 01-May-2018, tatu: I have a feeling this will need to be revisited at some point,
// to avoid removing some types of removals, possibly. But will do for now.
// 16-May-2020, tatu: ... and so the day came, [databind#2118] failed
// when explicit rename added to ignorals (for READ_ONLY) was suddenly
// removed from ignoral list. So, added a guard statement above so that
// ignoral is ONLY removed if there was matching creator property.
//
// Chances are this is not the last tweak we need but... that bridge then etc
if (_ignoredPropertyNames != null) {
_ignoredPropertyNames.remove(name);
}

given we're renaming to same property name, it's then removed from the ignorable list, I'm still unsure of how this should be fixed, so will try to tackle it in a separate PR, in this PR I marked the test as expected to fail so we're aware of it.

@iifawzi
Copy link
Contributor Author

iifawzi commented Apr 6, 2025

CLA signed earlier today for this repoisotry

@iifawzi iifawzi changed the title Fixing deserialization issues with read-access when json renamed to same property name Fixing records deserialization issues with read-access when json renamed to same property name Apr 6, 2025
iifawzi added 2 commits April 6, 2025 20:07
Signed-off-by: Fawzi Essam <[email protected]>
@cowtowncoder
Copy link
Member

2 quick questions:

  1. I think you are saying this does fix Duplicate creator property "b" (index 0 vs 1) on simple java record #5049, but not @JsonIgnore and @JsonProperty.access=READ_ONLY on Record property ignored for deserialization #4628 ?
  2. While there's some theoretical risk, I feel risk is low and it'd be good to actually target 2.18 branch (for 2.18.4) with this (or separate) PR? (note: I always merge forward so only one PR needed, but needs to target oldest minor version branch)

On (2), actually, I think I could try cherry-picking after merging this against 2.19 so that's probably fine.

@iifawzi
Copy link
Contributor Author

iifawzi commented Apr 6, 2025

2 quick questions:

  1. I think you are saying this does fix Duplicate creator property "b" (index 0 vs 1) on simple java record #5049, but not @JsonIgnore & @JsonProperty.access=READ_ONLY on Record property ignored for deserialization, if @JsonProperty.value is the same as the property name #4628 ?
  2. While there's some theoretical risk, I feel risk is low and it'd be good to actually target 2.18 branch (for 2.18.4) with this (or separate) PR? (note: I always merge forward so only one PR needed, but needs to target oldest minor version branch)

On (2), actually, I think I could try cherry-picking after merging this against 2.19 so that's probably fine.

@cowtowncoder
Copy link
Member

@iifawzi Ok if it's simple enough, separate PR against 2.18 would be ideal. If not, I can figure out cherry-picking.

This is excellent progress -- thank you very much for working on this!

@iifawzi
Copy link
Contributor Author

iifawzi commented Apr 6, 2025

@iifawzi Ok if it's simple enough, separate PR against 2.18 would be ideal. If not, I can figure out cherry-picking.

This is excellent progress -- thank you very much for working on this!

Thank you @cowtowncoder!
You can find #5073 targeting 2.18.

@cowtowncoder
Copy link
Member

Superceded by #5073, closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants