title: How to serialize list of enums from rest api
body: <p>I want to return a list of enums from a rest api call, and have it show the value of the enum rather than just the enum names, in JSON format.  Currently my rest call returns json looking like:</p>
  
  <pre><code>{
    "responses": [
      "ACTION_TAKEN",
      "IGNORED",
      "UNDETECTED"
    ]
  }
  </code></pre>
  
  <p>But, I want it to be more like (or something like this): </p>
  
  <pre><code>{
    "responses": [
      {
        "name":"ACTION_TAKEN",
        "value":"Action Taken"
      },
      {
        "name":"IGNORED",
        "value":"Ignored"
      },
      {
        "name":"UNDETECTED",
        "value":"Undetected"
      }
     ]
  }
  </code></pre>
  
  <p>My enum looks like: </p>
  
  <pre><code>public enum Response {
  
    ACTION_TAKEN ("Action Taken"),
    IGNORED ("Ignored"),
    UNDETECTED("Undetected");
  
    private String value;
  
    Response(String value) {
      this.value = value;
    }
  
    public String getValue() {
      return this.value;
    }
  
    @Override
    public String toString() {
      return value;
    }
  }
  </code></pre>
  
  <p>My model object looks like this.  For the sake of this example, it just has a list of enum values.</p>
  
  <pre><code>@XmlRootElement
  @XmlAccessorType(XmlAccessType.FIELD)
  public class StaticData {
  
    private List&lt;Response&gt; responses;
  
    public List&lt;Response&gt; getResponses() {
      return responses;
    }
  
    public void setResponses(List&lt;Response&gt; responses) {
      this.responses = responses;
    }
  }
  </code></pre>
  
  <p>The web service method looks like: </p>
  
  <pre><code>@Component
  @Path("staticData")
  @Produces("application/json")
  @Consumes("application/json")
  public class StaticDataResource {
  
    @GET
    public Response getCurrentContent() {
      StaticData staticData = new StaticData();
      staticData.setResponses(Arrays.asList(Response.values()));
      return Response.ok(staticData).build();
    }
  }
  </code></pre>
  
  <p>Here are the dependencies from my effective pom (sorry for the bad formatting)</p>
  
  <pre><code>&lt;dependencies&gt;
    &lt;dependency&gt;
      &lt;groupId&gt;org.springframework&lt;/groupId&gt;
      &lt;artifactId&gt;spring-aspects&lt;/artifactId&gt;
      &lt;version&gt;4.2.5.RELEASE&lt;/version&gt;
      &lt;scope&gt;compile&lt;/scope&gt;
    &lt;/dependency&gt;
    &lt;dependency&gt;
      &lt;groupId&gt;com.sun.jersey.contribs&lt;/groupId&gt;
      &lt;artifactId&gt;jersey-spring&lt;/artifactId&gt;
      &lt;version&gt;1.19.1&lt;/version&gt;
      &lt;scope&gt;compile&lt;/scope&gt;
      &lt;exclusions&gt;
        &lt;exclusion&gt;
          &lt;artifactId&gt;*&lt;/artifactId&gt;
          &lt;groupId&gt;org.springframework&lt;/groupId&gt;
        &lt;/exclusion&gt;
      &lt;/exclusions&gt;
    &lt;/dependency&gt;
    &lt;dependency&gt;
      &lt;groupId&gt;com.thetransactioncompany&lt;/groupId&gt;
      &lt;artifactId&gt;cors-filter&lt;/artifactId&gt;
      &lt;version&gt;2.4&lt;/version&gt;
      &lt;scope&gt;compile&lt;/scope&gt;
    &lt;/dependency&gt;
    &lt;dependency&gt;
      &lt;groupId&gt;org.springframework&lt;/groupId&gt;
      &lt;artifactId&gt;spring-aop&lt;/artifactId&gt;
      &lt;version&gt;4.2.5.RELEASE&lt;/version&gt;
      &lt;scope&gt;compile&lt;/scope&gt;
    &lt;/dependency&gt;
    &lt;dependency&gt;
      &lt;groupId&gt;org.springframework&lt;/groupId&gt;
      &lt;artifactId&gt;spring-webmvc&lt;/artifactId&gt;
      &lt;version&gt;4.2.5.RELEASE&lt;/version&gt;
      &lt;scope&gt;compile&lt;/scope&gt;
    &lt;/dependency&gt;
    &lt;dependency&gt;
      &lt;groupId&gt;org.springframework&lt;/groupId&gt;
      &lt;artifactId&gt;spring-expression&lt;/artifactId&gt;
      &lt;version&gt;4.2.5.RELEASE&lt;/version&gt;
      &lt;scope&gt;compile&lt;/scope&gt;
    &lt;/dependency&gt;
    &lt;dependency&gt;
      &lt;groupId&gt;org.springframework&lt;/groupId&gt;
      &lt;artifactId&gt;spring-oxm&lt;/artifactId&gt;
      &lt;version&gt;4.2.5.RELEASE&lt;/version&gt;
      &lt;scope&gt;compile&lt;/scope&gt;
    &lt;/dependency&gt;
  &lt;dependency&gt;
    &lt;groupId&gt;org.springframework&lt;/groupId&gt;
    &lt;artifactId&gt;spring-orm&lt;/artifactId&gt;
    &lt;version&gt;4.2.5.RELEASE&lt;/version&gt;
    &lt;scope&gt;compile&lt;/scope&gt;
  &lt;/dependency&gt;
  &lt;dependency&gt;
    &lt;groupId&gt;org.slf4j&lt;/groupId&gt;
    &lt;artifactId&gt;slf4j-api&lt;/artifactId&gt;
    &lt;version&gt;1.7.19&lt;/version&gt;
    &lt;scope&gt;compile&lt;/scope&gt;
  &lt;/dependency&gt;
  &lt;dependency&gt;
    &lt;groupId&gt;org.slf4j&lt;/groupId&gt;
    &lt;artifactId&gt;slf4j-log4j12&lt;/artifactId&gt;
    &lt;version&gt;1.7.19&lt;/version&gt;
    &lt;scope&gt;compile&lt;/scope&gt;
  &lt;/dependency&gt;
  &lt;dependency&gt;
    &lt;groupId&gt;commons-logging&lt;/groupId&gt;
    &lt;artifactId&gt;commons-logging&lt;/artifactId&gt;
    &lt;version&gt;1.2&lt;/version&gt;
    &lt;scope&gt;compile&lt;/scope&gt;
  &lt;/dependency&gt;
  &lt;dependency&gt;
    &lt;groupId&gt;commons-io&lt;/groupId&gt;
    &lt;artifactId&gt;commons-io&lt;/artifactId&gt;
    &lt;version&gt;2.4&lt;/version&gt;
    &lt;scope&gt;compile&lt;/scope&gt;
  &lt;/dependency&gt;
  &lt;dependency&gt;
    &lt;groupId&gt;com.google.guava&lt;/groupId&gt;
    &lt;artifactId&gt;guava&lt;/artifactId&gt;
    &lt;version&gt;19.0&lt;/version&gt;
    &lt;scope&gt;compile&lt;/scope&gt;
  &lt;/dependency&gt;
  &lt;dependency&gt;
    &lt;groupId&gt;org.reflections&lt;/groupId&gt;
    &lt;artifactId&gt;reflections&lt;/artifactId&gt;
    &lt;version&gt;0.9.10&lt;/version&gt;
    &lt;scope&gt;compile&lt;/scope&gt;
    &lt;exclusions&gt;
      &lt;exclusion&gt;
        &lt;artifactId&gt;guava&lt;/artifactId&gt;
        &lt;groupId&gt;com.google.guava&lt;/groupId&gt;
      &lt;/exclusion&gt;
    &lt;/exclusions&gt;
  &lt;/dependency&gt;
  &lt;dependency&gt;
    &lt;groupId&gt;javax.servlet&lt;/groupId&gt;
    &lt;artifactId&gt;javax.servlet-api&lt;/artifactId&gt;
    &lt;version&gt;3.0.1&lt;/version&gt;
    &lt;scope&gt;provided&lt;/scope&gt;
  &lt;/dependency&gt;
  &lt;dependency&gt;
    &lt;groupId&gt;javax.ws.rs&lt;/groupId&gt;
    &lt;artifactId&gt;javax.ws.rs-api&lt;/artifactId&gt;
    &lt;version&gt;2.0.1&lt;/version&gt;
    &lt;scope&gt;provided&lt;/scope&gt;
  &lt;/dependency&gt;
  &lt;dependency&gt;
    &lt;groupId&gt;org.eclipse.persistence&lt;/groupId&gt;
    &lt;artifactId&gt;javax.persistence&lt;/artifactId&gt;
    &lt;version&gt;2.1.0&lt;/version&gt;
    &lt;scope&gt;provided&lt;/scope&gt;
  &lt;/dependency&gt;
  &lt;dependency&gt;
    &lt;groupId&gt;javax.ejb&lt;/groupId&gt;
    &lt;artifactId&gt;javax.ejb-api&lt;/artifactId&gt;
    &lt;version&gt;3.2&lt;/version&gt;
    &lt;scope&gt;provided&lt;/scope&gt;
  &lt;/dependency&gt;
    &lt;dependency&gt;
        &lt;groupId&gt;javax.transaction&lt;/groupId&gt;
        &lt;artifactId&gt;jta&lt;/artifactId&gt;
        &lt;version&gt;1.1&lt;/version&gt;
        &lt;scope&gt;provided&lt;/scope&gt;
      &lt;/dependency&gt;
  &lt;/dependencies&gt;
  </code></pre>
  
  <p>I have tried adding <code>@JsonFormat(shape = JsonFormat.Shape.Object)</code> to the top of my enum class.  It didn't work.  I tried adding <code>@JsonValue</code> to above my getValue() method in the enum class, and that didn't work either.  I tried adding a custom serializer extending StdSerializer or JsonSerializer, and referencing that class above my enum using <code>@JsonSerialize(using = ReasonSerializer)</code>.  I put a breakpoint in the serialize method and didn't hit it, so that didn't work.  I looked a little bit at doing <code>implements ContextResolver&lt;ObjectMapper&gt;</code>, but couldn't quite figure that out, or whether that was even the right path to go down or not.</p>
  
  <p>Any help is greatly appreciated!  Thanks!</p>