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
public enum LaunchType {
HARD("Hard"),
SOFT("Soft");
private final String name;
@Override
@JsonValue
public String toString() {
return name;
}
}
In Spring data couchbase 4.X, Enums where persisted to database as HARD or SOFT
Once we upgraded to Spring data couchbase 5.X, Enums are persisted to database as Hard or Soft.
Why has the behaviour changed and can we move back to previous behaviour?
The text was updated successfully, but these errors were encountered:
Enums are now serialized and deserialized by the ObjectMapper (OtherConverters.EnumToObject and Boolean/Integer/StringToEnumConverter.
If you want your LaunchType to be serialized as HARD, SOFT, then you can create a method that returns that and annotate it with @JsonValue. Likewise, create a method annotated with @JsonCreator that takes those strings and returns the Enums.
@JsonValue
public String name(){
return super.name(); // I suppose name.toUpperCase() would work as well.
}
@JsonCreator
public LaunchType(String uppercaseName){
for(LaunchType e:LaunchType.values()){
if(values.name().equals(uppercaseName)){
name = values.name; // the mixed-case name, not the uppercase name()
return;
}
}
throw SomeDerializationException(...);
}
public enum LaunchType {
HARD("Hard"),
SOFT("Soft");
}
In Spring data couchbase 4.X, Enums where persisted to database as HARD or SOFT
Once we upgraded to Spring data couchbase 5.X, Enums are persisted to database as Hard or Soft.
Why has the behaviour changed and can we move back to previous behaviour?
The text was updated successfully, but these errors were encountered: