title: JAXB or JAX-RS is wrapping numbers in my JSON responses with quotes, turning them into strings. Why this is the default behavior, and how to fix it?
body: <p>I am currently working on a RESTful API. I have an Employee class and an EmployeeResource class. I also have a custom DateAdapter, which changes my Date properties to Long timestamps. However, my JSON responses are showing the timestamps as strings (wrapped in double quotes) rather than numbers (without double quotes). Here is an abbreviated version of my code and captured JSON response...</p>
  
  <p>Custom DateAdapter</p>
  
  <pre><code>public class DateAdapter extends XmlAdapter&lt;Long, Date&gt; {
      @Override
      public Date unmarshal(Long v) throws Exception {
          return new Date(Long.valueOf(v));  
      }
      @Override
      public Long marshal(Date v) throws Exception {
          return v.getTime();  
      }
  }
  </code></pre>
  
  <p>Entity Class</p>
  
  <pre><code>@Entity
  @javax.xml.bind.annotation.XmlRootElement
  @XmlType(propOrder={"createdOn","empId"})
  public class Employee implements Serializable {
      private Date createdOn;
      private Integer empId;
  
      @Column(nullable=false)
      @Temporal(TemporalType.TIMESTAMP)
      @XmlJavaTypeAdapter(DateAdapter.class)
      public Date getCreatedOn() {
          return createdOn;
      }
      public void setCreatedOn(Date createdOn) {
          this.createdOn = createdOn;
      }
  
      @Id
      @XmlID
      public Integer getEmpId() {
          return empId;
      }
      public void setEmpId(Integer empId) {
          this.empId = empId;
      }
  }
  </code></pre>
  
  <p>EmployeeResource</p>
  
  <pre><code>@Path("/Employees")
  @javax.xml.bind.annotation.XmlRootElement 
  @XmlType(propOrder={"hateoas","employees"})
  public class EmployeeResource {
      List&lt;Employee&gt; employees;
  
      public List&lt;Employee&gt; getEmployees() {
          return employees;
      }
      public void setEmployees(List&lt;Employee&gt; employees) {
          this.employees = employees;
      }
      @GET
      @Path("/{id}")
      @Produces("application/json")
      public Response getEmployee(@Context UriInfo ui, @PathParam("id") Integer id) {
          Session session = HibernateUtil.getSession();
          session.beginTransaction();
          Criteria criteria=session.createCriteria(Employee.class);
          criteria.add(Restrictions.eq("empId", new Integer(10150)));
          this.employees = criteria.list();
          return Response.ok(this).build();
      }
  }
  </code></pre>
  
  <p>Current JSON response</p>
  
  <pre><code>{
    "employees":{
      "createdOn":"1330915130163",
      "empId":"10150"
    }
  }
  </code></pre>
  
  <p>Expected JSON response</p>
  
  <pre><code>{
    "employees":{
      "createdOn":1330915130163,
      "empId":10150
    }
  }
  </code></pre>
  
  <p>I'm assuming that there's some way to prevent JAXB or JAX-RS from wrapping all numbers in quotes. Could someone guide me to where I could configure this?</p>
  
  <p>Thanks in advance!</p>
  
  <p>EDIT #1 2012.03.07
  Ok, so after some more researching, I think my problem is with the default JSONConfiguration.Notation being used, MAPPED . It looks like the NATURAL JSONConfiguration.Notation would get me what I want. However, I haven't found a clear example of how to apply that application wide. I'm assuming I would specify this in my ApplicationConfig class that extends javax.ws.rs.core.Application .</p>
  
  <p>EDIT #2 2012.03.10
  Ok, so after some more researching I decided to use the JSON parser library, Jackson. It seems to be the most complete JSON solution out there using just the default configuration. By default Dates are translated to their corresponding timestamps and serialized as numbers (w/o quotes). The only drawback I have come across is that Jackson currently does not support the JAXB annotations, "@XmlID" and "@XmlIDREF". Since I have direct self-references in my data model (not shown above), I have created another question to discuss. If anyone is interested <a href="https://stackoverflow.com/questions/9642031/how-to-get-around-jacksons-inability-to-handle-direct-self-references-in-jpa-be#comment12250938_9642031">click here to follow that thread...</a></p>