users@jersey.java.net

Re: [Jersey] How to append extra informaion to generated json

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Wed, 22 Apr 2009 09:47:40 +0200

Hi Sanjay,

Just curious as to why you want to do this when it can be derived
from the JSON data structures using JavaScript?

Having additional information like this also introduces the
possibility for errors if the total number of objects is declared is
different to the number of objects.


The easiest way to support this is for it to work for XML and JSON.

It may be possible to set the JAXB field for the total objects only
when JSON is the most acceptable. You can do this by calling the
HttpHeaders.getAcceptableMediaTypes() and checking if the first media
type is JSON related or XML related.


Another alternative is to not support XML if you do not need to. You
can still use JAXB of course.

Paul.

On Apr 21, 2009, at 8:37 PM, Patel, Sanjay wrote:

> Hey,
>
> I am using jersey/jaxb to convert my list of objects to JSON. I want
> to add extra property to my generated JSON (e.g "total":
> total_objects_in_list). How can I do that??
>
> Sanjay
>