Firebase 9.0.0枚举反序列化缺少的构造函数错误

时间:2016-05-20 15:00:09

标签: java android serialization firebase firebase-realtime-database

我在模型中使用的枚举字段看起来像

@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);
    }

}

0 个答案:

没有答案