title: How to exactly match json output from cxf?
body: <p><em><strong>Edit:</strong></em> i was confused-- were using cxf, not jersey. Is there a way to convert an annotated object to json that is similar to jackson's ObjectMapper?</p>
  
  <p><em>original msg:</em></p>
  
  <p>Hi,
  We are currently using jaxrs to convert our web responses to xml/json. What I would like to do now, however, is generate an equivalent json string inside my code using ObjectMapper(?).</p>
  
  <p>For instance, given a controller and jaxb-annotated return object:</p>
  
  <pre><code>@Path("/foo")
  @Produces({"application/json", "application/xml"})
  public class FooController {
  
      @GET
      @Path("/some_action")
      public TopDTO someAction(@QueryParam("arg") String arg) {
          ...
      }
  }
  
  @XmlRootElement(name="topDTO")
  @XmlAccessorType(XmlAccessType.NONE)
  public class TopDTO {
      ...
      @XmlAttribute(name="attr")
      public String getAttr() {
          return "blah";
      }
      @XmlElement(name="innerDTO")
      public InnerDTO getInnerDTO() {
         ...
      }
  }
  
  @XmlRootElement(name="innerDTO")
  @XmlAccessorType(XmlAccessType.NONE)
  public class InnerDTO {
      ...  
  }
  </code></pre>
  
  <p>Hitting <a href="http://myserver/.../foo.json" rel="nofollow">http://myserver/.../foo.json</a> puts out some pretty json:</p>
  
  <pre><code>{"topDTO":{"@attr":"blah","innerDTO":...}}
  </code></pre>
  
  <p>Now I would like to be able to generate that exact json internally:</p>
  
  <pre><code>ObjectMapper mapper = new ObjectMapper();
  AnnotationIntrospector introspector = new JaxbAnnotationIntrospector();
  mapper.getSerializationConfig().setAnnotationIntrospector(introspector);
  mapper.getSerializationConfig().setSerializationInclusion(Inclusion.ALWAYS);            
  mapper.getSerializationConfig().set(SerializationConfig.Feature.AUTO_DETECT_FIELDS, false);
  mapper.getSerializationConfig().set(SerializationConfig.Feature.WRAP_ROOT_VALUE, true);
  return mapper.writeValueAsString(snapshotDTO);
  </code></pre>
  
  <p>However, this doesn't seem to work at all; most of the annotated attributes and elements are missing, the attributes aren't prefixed with "@" as they are with jaxrs output, etc.</p>
  
  <p>Am i missing something simple? How does jaxrs itself convert an annotated object to a json string? </p>
  
  <p>Thanks!
  joe</p>