Closed mann-ed closed 8 years ago
Is there a way with enum to set that value field i want output when writing to json?
Such as
public enum DelayType { MIll(1, "Delay by milliseconds"), SEC(10, "Delay by seconds"), MIN(20, "Delay by minutes"), HOUR(30, "Delay by hour"), DAY(40, "Delay by day(s)"), YEAR(50, "Delay by years. HUM REALLY?"); private Integer delayCode; private String delayDesc; private DelayType(Integer delayCode, String delayDesc) { this.delayCode = delayCode; this.delayDesc = delayDesc; } /** * @return */ @JsonValue public Integer getDelayCode() { return this.delayCode; } /** * @return */ public String getDelayDesc() { return this.delayDesc; }
The field with @JsonValue is what i want to be placed in the output json.
@JsonValue
This is a feature request, or some direction on how i can get my desired output.
{"alertClosed":true,"delayType":"MIN","notifyDelay":14}
{"alertClosed":true,"delayType":20,"notifyDelay":14}
You can use @Ignore to ignore the fields and then expose the properties.
Is there a way with enum to set that value field i want output when writing to json?
Such as
The field with
@JsonValue
is what i want to be placed in the output json.This is a feature request, or some direction on how i can get my desired output.
Current Output:
{"alertClosed":true,"delayType":"MIN","notifyDelay":14}
Desired Outut:
{"alertClosed":true,"delayType":20,"notifyDelay":14}