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

fix: JSON deserialization setter case priority #1831

Merged
merged 2 commits into from
Mar 14, 2023
Merged

Conversation

meltsufin
Copy link
Member

Fixes the problem of JSON deserialization ignoring the case of setters. Now case-sensitive setter method matches are considered first.

Fixes: #1830.

Fixes the problem of JSON deserialization ignoring the case of setters.
Now case-sensitive setter method matches are considered first.

Fixes: #1830.
@meltsufin meltsufin requested a review from a team as a code owner March 11, 2023 04:09
@product-auto-label product-auto-label bot added the size: m Pull request size is medium. label Mar 11, 2023
@meltsufin meltsufin requested a review from a team March 11, 2023 04:10
// add case-sensitive matches first in the list
if (method.getName().equals(fieldSetter)) {
methods.add(0, method);
} else if (Ascii.toLowerCase(method.getName()).equals(Ascii.toLowerCase(fieldSetter))) {
Copy link
Member

@burkedavison burkedavison Mar 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wish I understood the reason behind this lowercase comparison better. It feels like it was an arbitrary implementation choice while fixing an issue, but I'm not sure.

I don't think we can change it after all this time, though.

Original PR: #538

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@suztomo I would like you opinion on whether this would considered a breaking change.

@meltsufin meltsufin requested a review from suztomo March 13, 2023 20:56
List<Method> methods = new ArrayList<>();
String fieldSetter = "set" + Ascii.toUpperCase(field.getName().substring(0, 1));
Copy link

@blakeli0 blakeli0 Mar 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This approach works for this issue, however, is it possible to have a scenario that the field name is utcTime, and the setter is setUTCTime? We may have to look at how GenericJson is implemented to confirm this. So I think it would be safer to split the method.getName() by set and compare the name with field.getName().

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default setter for utcTime would be setUtcTime(). So, I think this logic would work. The default setter would take precedence over setUTCTime().

@suztomo
Copy link
Member

suztomo commented Mar 14, 2023

I didn’t know this case priority behavior. If not done yet, can you write down the desired behavior about the setter case priority in the Javadoc? Include how it helps the users of this HTTP client library.

If the current implementation was not doing the job in the spec, then this PR is a bug fix.

@meltsufin
Copy link
Member Author

I didn’t know this case priority behavior. If not done yet, can you write down the desired behavior about the setter case priority in the Javadoc? Include how it helps the users of this HTTP client library.

If the current implementation was not doing the job in the spec, then this PR is a bug fix.

It's a bugfix. Internal ref: b/267807198.

@meltsufin meltsufin merged commit 30182e1 into main Mar 14, 2023
@meltsufin meltsufin deleted the fix-case-sensitivity branch March 14, 2023 03:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size: m Pull request size is medium.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

JSON deserialization ignores case of setters
4 participants