-
-
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
@JsonSetter(nulls = Nulls.SKIP)
doesn't work in some situations
#4441
Comments
Sorry late asking, but are the versions in "Version Informations" all that are not working? |
Yes, these are versions where the bug happens (didn't test older versions though). I first discovered this issue when using 2.15.3. Later I tried newer versions hoping that this was fixed, but the issue was still reproducible with all newer versions as well. |
Sorry late again @Asapin, one more question is which latest version did it work? 2.15.2? 👈🏼 Finding this out would help alot. I modified a bit around visibility of fields (and simplified a bit), it seems to work. If urgent, I guess possible work around would be modifying visilbity via public class BeanDeserializerModifier4216Test {
static class Outer {
@JsonSetter(nulls = Nulls.SKIP)
public List<Middle> list1 = new ArrayList<>();
}
static class Middle {
@JsonSetter(nulls = Nulls.SKIP)
public List<Inner> list1 = new ArrayList<>();
public String field1;
}
static class Inner {
private final String field1;
@ConstructorProperties({"field1"})
public Inner(String field1) {
this.field1 = field1;
}
public String getField1() {
return field1;
}
}
public static void main(String[] args) {
try {
Outer outer = new ObjectMapper().readValue("""
{
"list1": [
{
"list1": null,
"field1": "data"
}
]
}""", Outer.class);
validateNotNull(outer);
validateNotNull(outer.list1);
for (Middle middle : outer.list1) {
validateNotNull(middle);
validateNotNull(middle.field1);
validateNotNull(middle.list1);
}
} catch (JsonProcessingException e) {
throw new RuntimeException(e);
}
}
private static void validateNotNull(Object o) {
if (o == null) {
throw new IllegalStateException("Shouldn't be null");
}
}
} |
@JooHyukKim |
Strange... seems like bug. If you can either...
as a temporary work-around, that'd be great 👍🏼 |
Changing order might suggest the issue has something to do with buffering (as buffering only needed in some cases depending on input order of content). |
Ahhh. Actually, it is sort of due to buffering... but quite indirectly. @JooHyukKim figured it out; it's missing logic from |
@JsonSetter(nulls = Nulls.SKIP)
doesn't work in some situations
Search before asking
Describe the bug
We're using
@JsonSetter(nulls = Nulls.SKIP)
quite heavily in our code base to avoid dealing withnull
values, but yesterday I noticed that some fields containnull
despite being annotated with@JsonSetter(nulls = Nulls.SKIP)
Version Information
2.15.3, 2.15.4, 2.16.0, 2.16.1, 2.16.2, 2.17.0
Reproduction
Expected behavior
middle.getList1()
shouldn't benull
since it's annotated with@JsonSetter(nulls = Nulls.SKIP)
Additional context
Any of the following seems to fix the issue, but is not really feasible to do:
final
fromMiddle#field1
and remove this field from constructor parametersThe text was updated successfully, but these errors were encountered: