users@jersey.java.net

_at_XmlRootElement not shown in a JSON response

From: Grover Blue <grover.blue_at_gmail.com>
Date: Fri, 21 Aug 2009 12:30:15 -0400

 Shouldn't the root "record" be included with a JSON response?

@XmlRootElement(name="record")
public class ReturnedClass {

    private String term;
    private Date time;

    @XmlElement(name="searchTerm")
    public String getTerm() { return term; }

    @XmlTransient
    public Date getTime() { return time; }

    @XmlElement(name="searchTime")
    public long getTimeInMilliseconds() { return time.getTime();}

}


*Result:*
{
  "searchTerm":"myTerm",
  "searchTime":"987654321"
}

*Expected:*
{
  "record" : {
    "searchTerm":"myTerm",
    "searchTime":"987654321"
  }
}


*This is the resource method:*

    @GET
    @Path("/myPath/{searchTerm}/{searchTime}")
    @Produces("application/json")
    public ReturnedClass getResult(@PathParam("searchTerm") String term,
                                     @PathParam("searchTime") long
milliseconds) {
        ReturnedClass rc = new ReturnedClass();
        rc.setTerm(term);
        rc.setTime(new Date(milliseconds));
        return rc;
    }