users@jersey.java.net

Re: [Jersey] _at_XmlRootElement not shown in a JSON response

From: Tatu Saloranta <tsaloranta_at_gmail.com>
Date: Sun, 23 Aug 2009 07:32:17 -0700

Doesn't that depend on which convention is being used? For some it
should, for others not -- it's not strictly required information.

-+ Tatu +-

On Fri, Aug 21, 2009 at 9:30 AM, Grover Blue<grover.blue_at_gmail.com> wrote:
> 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;
>     }
>