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

@Jsonsetter with Nulls.SKIP collides with DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL when parsing enum #2015

Closed
ndori opened this issue Apr 30, 2018 · 1 comment
Milestone

Comments

@ndori
Copy link

ndori commented Apr 30, 2018

Hi, I've noticed a behavior I think should be different with
@jsonsetter(value = "foo", nulls = Nulls.SKIP)
private String foo;
and with .configure(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL, true)

in that case, I would expect that if there is an unknown enum the setter will skip the null set, as I told him I don't want you to set null.

but what is probably happening is that it sees a value which is not null so it tries to set it, then when it can't set it, it becomes null.

I realize that it will be probably hard to fix, but on the other hand, the whole point of the nulls attribute is to do something else with nulls...

test case:

    public enum NUMS{
        ONE, TWO
    }

    public static class Pojo {
        @JsonSetter(value = "number", nulls = Nulls.SKIP)
        NUMS number = NUMS.TWO;
    }
    public void foo() {
        ObjectMapper parser = new ObjectMapper();
        parser.configure(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL, true);

        String json = "{\"number\":\"THREE\"}";

        try {
            Pojo p = parser.readValue(json, Pojo.class);
            //p.number == null , should be TWO
        } catch (IOException e) { }
    }
@cowtowncoder cowtowncoder added this to the 2.9.6 milestone May 5, 2018
@cowtowncoder cowtowncoder changed the title @Jsonsetter with Nulls.SKIP collide with DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL when parsing enum @Jsonsetter with Nulls.SKIP collides with DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL when parsing enum May 5, 2018
@cowtowncoder
Copy link
Member

I think this had the same root cause as #2023; test now passes in 2.9 so fix will be in 2.9.6

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