serialization for enum

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.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s