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

@JsonCreator to deserialize BigInteger to Enum #560

Closed
ghost opened this issue Sep 26, 2014 · 3 comments
Closed

@JsonCreator to deserialize BigInteger to Enum #560

ghost opened this issue Sep 26, 2014 · 3 comments
Milestone

Comments

@ghost
Copy link

ghost commented Sep 26, 2014

I want to use @JsonCreator to deserialize BigInteger to Enum.

public enum TestEnum {

    AAA(BigInteger.valueOf(1)),
    BBB(BigInteger.valueOf(2));

    private TestEnum(BigInteger key) {
        this.key = key;
    }

    private BigInteger key;

    @JsonValue
    public BigInteger getKey() {
        return this.key;
    }

    @JsonCreator
    public static TestEnum valueOf(BigInteger key) {
        /* ... BigInteger to TestEnum ... */
        return _enum;
    }
}

Now, @JsonCreator compatible with String, Integer, and Long. So, I get IllegalArgumentException.
https://github.com/FasterXML/jackson-databind/blob/master/src/main/java/com/fasterxml/jackson/databind/deser/std/EnumDeserializer.java#L41-L51

and user cannot change EnumDeserializer class (need to custormize BasicDeserializerFactory).
https://github.com/FasterXML/jackson-databind/blob/master/src/main/java/com/fasterxml/jackson/databind/deser/BasicDeserializerFactory.java#L1222

I know about @JsonDeserialize and SimpleModule, but they take time applying to each Enums.

Is it possible to add BigInteger deserializing for @JsonCreator ?

@cowtowncoder
Copy link
Member

Sounds like implementation is incomplete. Yes, ideally any type should be usable that way.
Apologies for trouble & thank you for reporting this.

@ghost
Copy link
Author

ghost commented Sep 26, 2014

Wow! Thank you for considering my request!

@cowtowncoder
Copy link
Member

Implemented, will be in 2.5.0.

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

1 participant