I have this Java enum:
public enum UserTypeEnum implements EnumConverter {
USER(1),
USERS_GROUP(2);
private final int type;
UserTypeEnum(int type) {
this.type= type;
}
@Override
@JsonValue
public int getType() {
return type;
}
}
With the simple interface:
public interface EnumConverter {
int getType();
}
I put the @JsonValue annotation above the getType method as I wanted these objects to appear in the JSON as integers. The problem is that when Jackson tries to deserialize them, I get:
com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Cannot construct instance of `UserTypeEnum` (no Creators, like default constructor, exist): no int/Int-argument constructor/factory method to deserialize from Number value (1) at {"type":1}
Even though the constructor exists. I want Jackson to use either the constructor or the getType method in deserialization. How can I achieve that?