I have the following enum:
public enum ChangeMode {
None(1), Add(2), Update(3), Delete(4);
// String value
public String getStringValue() {
return name();
}
public static ChangeMode getEnumValue(String v) {
return valueOf(v);
}
public static ChangeMode getEnumValue(int intValue) {
for (ChangeMode x : values())
if (Objects.equals(x.intValue, intValue))
return x;
return null;
}
// Int value
private int intValue;
private ChangeMode(int intValue) {
this.intValue = intValue;
}
public int getIntValue() {
return this.intValue;
}
}
Notice the enum values start from 1-4 and not 0-3.
I'm using Wildfly and Jackson.
When I'm getting the value 4 from the client JSON (using HTTP POST) I'm getting the following error:
Can not construct instance of com.ta9.enums.ChangeMode from number value (4): index value outside legal index range [0..3] at [Source: org.glassfish.jersey.message.internal.ReaderInterceptorExecutor$UnCloseableInputStream@55a6e779; line: 770, column: 26] (through reference chain: