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

Bug @JsonProperty default value in versions 2.8.3 and 2.8.4 #1420

Closed
Alexuy opened this issue Oct 17, 2016 · 1 comment
Closed

Bug @JsonProperty default value in versions 2.8.3 and 2.8.4 #1420

Alexuy opened this issue Oct 17, 2016 · 1 comment

Comments

@Alexuy
Copy link

Alexuy commented Oct 17, 2016

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}

@cowtowncoder
Copy link
Member

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

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

No branches or pull requests

2 participants