我在模型中使用的枚举字段看起来像
@JsonProperty("status")
public Status getStatus() {
return status;
}
@JsonProperty("status")
public void setStatus(Status status) {
this.status = status;
}
以前当firebase使用jackson时。它工作正常。
现在它将枚举序列化为
--status
|
--value: "OPEN"
但是当它反序列化时,它显示错误为
com.mypackage.app.models.Order$Status is missing a constructor with no arguments
使用jackson我使用注释来自定义序列化/反序列化。
这就是Status
enum的样子
public enum Status {
OPEN, ACKNOWLEDGED, CONFIRMED, CANCELED, COMPLETED;
Status() {
}
String value;
@JsonValue
public String getValue() {
// return this.ordinal();
return this.name();
}
@JsonCreator
public static Status fromValue(String statusString) {
for (Status c : Status.values()) {
if (c.name().equals(statusString)) {
return c;
}
}
throw new IllegalArgumentException("Invalid Status type code: " + statusString);
}
}