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

JsonFormat.Shape.NUMBER_INT does not work when defined on enum type in 2.8 #1543

Closed
panchenko opened this issue Mar 5, 2017 · 3 comments
Closed
Milestone

Comments

@panchenko
Copy link

Before 2.8 the following worked for years. Now this annotation is not applied and enum is serialized as string. It would work if annotating the field. I am not sure if this is an expected change or not, could you please check?

public class Test {
    @JsonFormat(shape = JsonFormat.Shape.NUMBER_INT)
    enum Color {
        RED,
        YELLOW,
        GREEN
    }

    static class Foo {
        public final Color color;

        Foo(Color color) {
            this.color = color;
        }
    }

    public static void main(String[] args) throws JsonProcessingException {
        final ObjectMapper mapper = new ObjectMapper();
        System.out.println(mapper.writeValueAsString(new Foo(Color.GREEN)));
    }
}
@cowtowncoder
Copy link
Member

@panchenko Good question. If this did work until 2.7 (which I think is what you are saying), I think it should still work. Things do get bit complicated with 2.8 and later due to all the levels at which configuration works (esp. regarding new "config overrides", see `ObjectMapper.configOverrides()).
But I think annotation-based per-type overrides have their place so I hope this can be fixed.

@panchenko
Copy link
Author

panchenko commented Mar 6, 2017

@cowtowncoder Yes, I mean it worked in versions [2.1.*, 2.7.*]

@cowtowncoder cowtowncoder removed the 2.9 label Mar 8, 2017
cowtowncoder added a commit that referenced this issue Mar 8, 2017
@cowtowncoder cowtowncoder removed the 2.8 label Mar 8, 2017
@cowtowncoder cowtowncoder added this to the 2.8.8 milestone Mar 8, 2017
@cowtowncoder
Copy link
Member

Yes, there was a subtle bug in there which lead to class annotation's effects be (accidentally) overwritten by default config overrides. Thank you for reporting this; fix will be in 2.8.8.

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