【发布时间】:2016-09-25 06:32:59
【问题描述】:
我希望使用 apiValue (SUN, MON, ...) 而不是枚举值 (SUNDAY, MONDAY, ....) 对以下枚举进行序列化/反序列化。我使用 @JsonValue 注释,但它不起作用(即它使用枚举值)。知道如何解决这个问题吗?
import java.util.*;
import com.fasterxml.jackson.annotation.JsonValue;
public enum ApiNotificationScheduleDayInWeek {
SUNDAY("SUN", 1),
MONDAY("MON", 2),
TUESDAY("TUE", 3),
WEDNESDAY("WED", 4),
THURSDAY("THU", 5),
FRIDAY("FRI", 6),
SATURDAY("SAT", 7),
WEEKDAY("WEEKDAY", 8),
WEEKEND("WEEKEND", 9);
private String apiValue;
private Integer intValue;
@JsonValue
public String getApiValue() {
return apiValue;
}
private ApiNotificationScheduleDayInWeek(String apiValue, Integer intValue) {
this.apiValue = apiValue;
this.intValue = intValue;
}
}
【问题讨论】:
-
请出示序列化码。一个minimal reproducible example。