If you are using Jackson 1.9, serialization would be done by:
public enum BooleanField {
BOOLEAN_TRUE("1")
;
// either add @JsonValue here (if you don't need getter)
private final String value;
private BooleanField(String value) { this.value = value; }
// or here
@JsonValue public String value() { return value; }
so change you need is to add method to Enum type itself, so all values have it. Not sure if it would work on subtype.
For @JsonCreator
, having a static factory method would do it; so adding something like:
@JsonCreator
public static BooleanField forValue(String v) { ... }
Jackson 2.0 will actually support use of just @JsonValue
for both, including deserialization.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…