Skip to content

@JsonCreator not working on a factory with multiple arguments for a enum typeΒ #929

@logic-1

Description

@logic-1

Using a factory method having multiple arguments annotated with @JsonCreator works normally when the factory is for a class type, but fails if the factory is for an enum type.

jackson-databind v 2.5.1
jackson-annotations v 2.5.0

e.g. code

String json = "{\"intProp\":1,\"stringProp\":\"first\"}";
ObjectMapper mapper = new ObjectMapper();

MyClass classValue = mapper.readValue(json, MyClass.class); //works
MyEnum enumValue = mapper.readValue(json, MyEnum.class); //fails 

both MyClass and MyEnum has a method like

@JsonCreator(mode = JsonCreator.Mode.PROPERTIES)
public static MyClass/MyEnum forValues(@JsonProperty("intProp") int intProp, @JsonProperty("stringProp") String stringProp){

        /// logic to create an instance with params using int
        // in case of enum find the appropriate object. 
        return object; 
}

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