-
-
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
Non default value skipped in serialized json with serialization inclusion NON_DEFAULT #2105
Comments
This issue also burned us when upgrading from 2.6.6 to 2.9.6. It was extra confusing because of the breaking changes with This also changed with String. Previously I'm reading a bunch of other tickets relating #1351 and I'm sympathetic because it's hard to know what the right answer is. But it would be great to know if this is a bug that's going to be fixed (and thus we might upgrade to 2.8.2) or if this is future functionality and we need to fix this in our application. |
At this point my goal is to try to make behavior match documentation, which I think states that meaning of When attached to a POJO Class (via class annotation, or In other cases, including that of global default (serialization inclusion), NON_DEFAULT excludes values of default value of that type (which is straight-forwards for primitives and their matching wrappers; "" for String; "absent" for Reference Types (Optional et al), timestamp The reason for such a complex setup is technical: figuring out default POJO property values can only be done when constructing POJO serializer (or at very least, that's what I concluded when trying to add new configuration levels). For Jackson 3.0 I can try to unify things to try to make POJO-defaults work in all cases; and type-default only where not applicable (when referenced as non-POJO property, such as root value or element of an array, Collection or Map). |
@cowtowncoder Okay, I understand. That definitely makes it harder for us. I think it's worth amending the 2.8 and 2.8.3 release notes to list this as a breaking change to help give others a forewarning. |
I would appreciate to see a unification. The behavior in 2.8.3 and later is counter-intuitive in my opinion. I’ve constructed a workaround to get the pre-2.8.3 behavior in 2.9.6: BeanSerializerFactoryWithGlobalIncludeDefaults.java Usage example: ObjectMapper mapper = new ObjectMapper();
mapper.setSerializerFactory(new BeanSerializerFactoryWithGlobalIncludeDefaults());
mapper.setSerializationInclusion(Include.NON_DEFAULT); |
Is there anyone who has a work around to fall back to the behaviour prior to 2.8.3 ? |
I've also encountered this quite contr-intuitive behaviour and may be the tests below can be useful to fix it or at least to be aware of it. |
@Rolly992 what you think is "default value" is not actually specification of what Jackson means by default PROPERTY value for deserialization purposes. Before sharing your personal interpretation of a term it makes sense to try to learn its meaning in context. But to recap: idea of default value for, say public class MyValue {
public int x, y;
public MyValue() {
x = 3;
y = 7;
}
// getters and setters is that default value for |
Running following code:
with Jackson v 2.8.2 outputs
{"value":false}
(as I expected). This however changes starting with 2.8.3: it outputs{}
(tested with 2.8.3, 2.8.11.2 and 2.9.6). I guess it was affected by #1351. Was it intended? Imo that's bug: default value forBoolean
isnull
, notfalse
.The text was updated successfully, but these errors were encountered: