users@jersey.java.net

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

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Mon, 24 Aug 2009 08:17:17 +0200

On Aug 23, 2009, at 4:32 PM, Tatu Saloranta wrote:

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

Yes.

See here for the JSON support in Jersey:

   https://jersey.dev.java.net/documentation/1.1.1-ea/user-
guide.html#json
   https://jersey.dev.java.net/documentation/1.1.1-ea/user-
guide.html#json.jaxb.mapped.root.unwrapping

Paul.

> -+ 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;
>> }
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>