【发布时间】:2023-03-07 05:23:01
【问题描述】:
我有一个这样的枚举类 -
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;
如何将其存储为字符串?
【问题讨论】:
标签: java android database enums