Gregg Gregg - 1 year ago 58
JSON Question

Wanting to get Enum Value instead of name in JSON

I've got the following enum:

public enum NotificationType {


public String value;

NotificationType(String value) {
this.value = value;

public String toString() {
return this.value;

public static NotificationType fromValue(String value) {
for (NotificationType type : NotificationType.values()) {
if (type.value.equals(value)) {
return type;
throw new IllegalArgumentException();

I've created a converter so that when the enum is saved to the database, it persists the value (S, E, D or A) instead of the name. And I can
json to the controller with the value and it binds to the object correctly.

However, when I render the JSON from a
it is still displaying the name (Employee, Store, etc) and I would prefer that it still show the value.

Answer Source

Because your toString method returns the value you want to use to represent your enum, you can annotate it with @JsonValue to tell Jackson that the return value represents the value of the enum.