serialization for enum

Jackie
May 10, 2021

--

turns out when serialization for Enum, instead of customizing the serializer to customize the output, it’s possible to annotate the method or field with @JsonValue.

enum Mode{
FLIGHT("AIRBUS"), ROAD("Tesla");
Mode(String instance){
..
}
@JsonValue
String instance;
}

this would then give out "AIRBUS" and "TESLA" instead of FLIGHT and ROAD.

--

--

No responses yet