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

Make FieldProperty skip nulls on set() method #4455

Closed
wants to merge 6 commits into from

Conversation

JooHyukKim
Copy link
Member

fixes #4441

As per comment, the problem seems to be around buffering + ordering of fields (implementing current PR made me believe more so). But since buffer sort of buffers by natural ordering of input JSON, I figured maybe we can just skip nulls within the field itself.

PS : target branch TBD

@cowtowncoder
Copy link
Member

But what about MethodPropertyies?

On target branch: I would not make risky change like this for patch, esp. not 2.15.

@JooHyukKim
Copy link
Member Author

JooHyukKim commented Mar 29, 2024

But what about MethodPropertyies?

Great question, I added test for method also.
You can see the test failing (link to failing GH action).

Observation is that....

  • Case for FieldProperty is just set to null
  • Case for MethodProperty also null is passed to the setter
    • In the test class I added Objects.requireNonNull() check on the setter method.

basically both field & method case null is passed.

@JooHyukKim
Copy link
Member Author

On target branch: I would not make risky change like this for patch, esp. not 2.15.

hmmm 2.17 while it's still RC then?

@cowtowncoder
Copy link
Member

cowtowncoder commented Mar 29, 2024 via email

@JooHyukKim
Copy link
Member Author

JooHyukKim commented Mar 29, 2024

2.17.0 was released 😀

Oh... haha
Changed target branch accordingly 👍🏼

@JooHyukKim JooHyukKim changed the base branch from 2.15 to 2.18 March 29, 2024 03:44
private final List<Inner> listInner = new ArrayList<>();
private final String field1;

@ConstructorProperties({"field1"})
Copy link
Member

Choose a reason for hiding this comment

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

Let's change this to use @JsonCreator instead to reduce use of @ConstructorProperties (in JPMS it's in extra package)

@@ -186,6 +186,12 @@ public Object deserializeSetAndReturn(JsonParser p,
@Override
public void set(Object instance, Object value) throws IOException
{
// [databind#4441] 2.17 Fix `@JsonSetter(Nulls.SKIP)` field is not skipped up to this point
if (value == null) {
Copy link
Member

Choose a reason for hiding this comment

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

Same also needed for setAndReturn() method, I think.

@@ -0,0 +1,149 @@
package com.fasterxml.jackson.databind.deser;
Copy link
Member

Choose a reason for hiding this comment

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

I think Nulls.SKIP tests are under src/test/java/com/fasterxml/jackson/databind/deser/filter/ typically?

@cowtowncoder
Copy link
Member

cowtowncoder commented Apr 6, 2024

@JooHyukKim Ok sorry, I think this could actually be added in 2.17(.1) if it is possible to rebase PR. Change is safer than I originally thought.

And yeah looks like skipping was accidentally omitted, probably assuming that the other 2 combo-methods would always be called. But that is not true for buffering cases.
So I think this is proper fix. Just need to tackle couple of things I mentioned.

@JooHyukKim
Copy link
Member Author

JooHyukKim commented Apr 6, 2024

@JooHyukKim Ok sorry, I think this could actually be added in 2.17(.1) if it is possible to rebase PR. Change is safer than I originally thought.

Alright, will apply your review and try to create separate PR instead.
Rebasing backward complicates things too much 🥲.

PS: filed #4469 accordingly.

@JooHyukKim JooHyukKim closed this Apr 6, 2024
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.

@JsonSetter(nulls = Nulls.SKIP) doesn't work in some situations
2 participants