我有一个像这样的枚举类 -
public enum FeedbackStatus {
@JsonProperty("unprocessed")
UNPROCESSED("unprocessed"),
@JsonProperty("arrived")
ARRIVED("arrived"),
@JsonProperty("performed")
PERFORMED("performed"),
@JsonProperty("cancelled")
CANCELLED("cancelled"),
@JsonProperty("removed")
REMOVED("removed"),
@JsonProperty("no-show")
NO_SHOW("no-show"),
@JsonProperty("cancel-at-door")
CANCEL_AT_DOOR("cancel-at-door");
private static final FeedbackStatus[] myEnumValues = FeedbackStatus.values();
private final String fieldDescription;
private FeedbackStatus(String value) {
this.fieldDescription = value;
}
public static FeedbackStatus fromString(String string) {
if (!TextUtils.isEmpty(string)) {
for (FeedbackStatus feedbackStatus : myEnumValues) {
if (feedbackStatus.getString().equalsIgnoreCase(string)) {
return feedbackStatus;
}
}
}
throw new IllegalArgumentException("No constant with text " + string + " found");
}
public String getString() {
return this.fieldDescription;
}
}
我需要使用 GreneDAO 在 SQLITE 数据库中存储一个对象 feedback
但该对象是一个枚举,因此我无法存储它。对象就像 -
private FeedbackStatus feedback;
如何将其存储为字符串?
最佳答案
用于前。已取消。值?什么时候存储数据?还有 ENUM.toString()。您可以将其存储为 String,然后使用 String to Enum 方法将恢复数据包装起来。
关于java - 要存储在数据库中的枚举,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39168939/