You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
publicenumMyType {
V1("val1"),
V2("val2"),
V3("val3"),
V4("val4"),
V5("val5"),
V6("val6");
privatefinalStringname;
MyType(Stringname) {
this.name = name;
}
publicstaticMyTypefromString(Stringname) {
for (MyTypetype : MyType.values()) {
if (type.name.equals(name)) {
returntype;
}
}
// In case no matching delegate to default parser which will throw a// IllegalArgumentException if it's unable to parse the namereturnMyType.valueOf(name.toUpperCase());
}
@OverridepublicStringtoString() {
returnname;
}
}
The text was updated successfully, but these errors were encountered:
flozano
changed the title
Backward-incompatible behaviour of 2.8
Backward-incompatible behaviour of 2.8: deserializing enum types with two static factory methods fail by default
Jul 7, 2016
Interesting. Thank you for reporting this; it is a flaw and change is unintentional. Not sure how it came about: static methods should not be auto-detected (unlike possibly single-string-constructors) but should require @JsonCreator. Possibly this is due to now skipping of constructor detection for enums (which caused another issue).
One quick note: a work-around is to explicitly annotate the creator with @JsonCreator: this removes ambiguity.
Problem itself comes from valueOf(), generated automatically by Java compiler (for enum types), being implicitly found; and then Jackson also accepting fromString(String), and because both are implicit, deserializer creator considers it ambiguous. What is less clear is how and why did 2.7 and earlier NOT fail with this one.
I'll try to find an improvement to alleviate the need, but I think addition of @JsonCreator actually makes sense here regardless.
After upgrading to 2.8, I'm getting:
Whereas in previous (2.7.x) it worked well.
The enum is defined as:
The text was updated successfully, but these errors were encountered: