Skip to content

@JsonCreator to deserialize BigInteger to Enum #560

@ghost

Description

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 ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions