Skip to content

Backward-incompatible behaviour of 2.8: deserializing enum types with two static factory methods fail by default #1291

@flozano

Description

@flozano

After upgrading to 2.8, I'm getting:

com.fasterxml.jackson.databind.JsonMappingException: Conflicting String creators: already had explicitly marked [method com.company.MyType#valueOf(1 params)], encountered [method com.company.MyType#fromString(1 params)]

Whereas in previous (2.7.x) it worked well.

The enum is defined as:

public enum MyType {

    V1("val1"),
    V2("val2"),
    V3("val3"),
    V4("val4"),
    V5("val5"),
    V6("val6");

    private final String name;

    MyType(String name) {
        this.name = name;
    }

    public static MyType fromString(String name) {
        for (MyType type : MyType.values()) {
            if (type.name.equals(name)) {
                return type;
            }
        }
        // In case no matching delegate to default parser which will throw a
        // IllegalArgumentException if it's unable to parse the name
        return MyType.valueOf(name.toUpperCase());
    }

    @Override
    public String toString() {
        return name;
    }
}

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