You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm using annotation @JsonProperty(defaultValue = "1") for my property. I have ObjectMapper with serialization setting 'JsonInclude.Include.NON_DEFAULT'. But after serializing i have a String-object with this property with default value.
Sample class:
public class A {
@JsonProperty(defaultValue = "1")
private int a = 1;
public int getA() {
return a;
}
public void setA(int a) {
this.a = a;
}
}
Serializing object in String with version 2.8.2: {}
Serializing object in String with version 2.8.3 or 2.8.4: {a:1}
The text was updated successfully, but these errors were encountered:
Quick note: defaultValue will have absolutely no effect on deserialization; it is only passed as metadata for (JSON) Schema generation.
As to output, 2.8.3 and later are as expected: global NON_DEFAULT setting will only check type defaults (for int that would be 0), and not POJO defaults for the type.
Only class annotation can be used to enable checks using "default POJO" instance: so in this case, you would have to add @JsonInclude(Include.NON_DEFAULT) for class A definition; global default will not work.
It is unfortunate if 2.8.2 behaved differently; it should not have excluded the value.
Behavior change is probably related to fix of #1351 that was included in 2.8.3
I'm using annotation @JsonProperty(defaultValue = "1") for my property. I have ObjectMapper with serialization setting 'JsonInclude.Include.NON_DEFAULT'. But after serializing i have a String-object with this property with default value.
Sample class:
Serializing object in String with version 2.8.2: {}
Serializing object in String with version 2.8.3 or 2.8.4: {a:1}
The text was updated successfully, but these errors were encountered: