title: Customize Json Output with Jersey and Jaxb
body: <p>I am trying to create a simple web service which outputs using json, but am not getting the desired Json output.</p>
  
  <p>POJO:
      package com.rest.resource;</p>
  
  <pre><code>import java.io.Serializable;
  import javax.xml.bind.annotation.XmlElement;
  import javax.xml.bind.annotation.XmlRootElement;
  
      @XmlRootElement
      @XmlAccessorType(XmlAccessType.FIELD)
      public class Track implements Serializable
         {
  
         @XmlElement
         String   singer   = "ABC";
         @XmlElement
         String   title    = "XYZ";
         }
  </code></pre>
  
  <p>Service:</p>
  
  <pre><code>import javax.ws.rs.Consumes;
  import javax.ws.rs.GET;
  import javax.ws.rs.POST;
  import javax.ws.rs.Path;
  import javax.ws.rs.Produces;
  import javax.ws.rs.core.MediaType;
  import javax.ws.rs.core.Response;
  import javax.xml.bind.JAXBException;
  import com.rest.resource.Track;
  
  @Path("/json/metallica")
  public class JSONService
     {
  
     @POST
     @Path("/post")
     @Consumes(MediaType.APPLICATION_JSON)
     @Produces(MediaType.APPLICATION_JSON)
     public Track createTrackInJSON(final Track track)
        {
         return track;
        }
  
     @GET
     @Path("/get")
     @Produces(MediaType.APPLICATION_JSON)
     public Response getTrackInJSON() throws JAXBException
        {
        final Track track = new Track();
        return Response.status(201).entity(track).build();
        }
  
     }
  </code></pre>
  
  <p>On /get I get</p>
  
  <p>{"singer":"ABC","title":"XYZ"}</p>
  
  <p>but I want "track": {"singer":"ABC","title":"XYZ"}
  I am unable yo print the root element.</p>
  
  <p>I tried using a CustomJAXBContextResolver class but did not work for me? Can anyone give an example of the same?</p>