users@jersey.java.net

Re: [Jersey] JSON and arrays of length one

From: Jakub Podlesak <Jakub.Podlesak_at_Sun.COM>
Date: Fri, 06 Nov 2009 17:39:19 +0100

On Fri, Nov 06, 2009 at 09:24:55AM -0600, FSauer_at_dsthealthsolutions.com wrote:
> How do I get arrays of length one out of jersey's JSON marshaller?
>
> If some object has a List<X> and there happens to be only one element in
> the collection, it comes across as" xs": {...X stuff here } instead of
> "xs" : [{...X stuff here }]....
> This is causing a lot of pain on the javascript side. Is there a fix for
> this? Am I missing some JSON configuration perhaps?

This should be described in [1]. All you need is to switch
to "natural" json notation (see section 3.1.2.2), i.e. to implement your own
JAXBContext resolver (see example 3.4, [2]).

HTH,

~Jakub

[1]https://jersey.dev.java.net/documentation/1.1.3-ea/user-guide.html#d4e536
[2]https://jersey.dev.java.net/documentation/1.1.3-ea/user-guide.html#json.jaxb.context.resolver.example

>
>
> Thanks,
>
>
> Frank Sauer
> Principal Architect
> DST Health Solutions
> 2500 Corporate Drive
> Birmingham, AL 35242
> (205)437-5204 (Office) (Direct)
> (205)568-4684 (Cell)
> fsauer_at_dsthealthsolutions.com
> It is impossible to sharpen a pencil with a blunt axe. It is equally vain
> to try to do it with ten blunt axes instead -- Edsger W. Dijkstra
>
>
> -----------------------------------------
> Please consider the environment before printing this email and any
> attachments.
>
> This e-mail and any attachments are intended only for the
> individual or company to which it is addressed and may contain
> information which is privileged, confidential and prohibited from
> disclosure or unauthorized use under applicable law. If you are
> not the intended recipient of this e-mail, you are hereby notified
> that any use, dissemination, or copying of this e-mail or the
> information contained in this e-mail is strictly prohibited by the
> sender. If you have received this transmission in error, please
> return the material received to the sender and delete all copies
> from your system.



-- 
Jakub Podlešák
Software Engineer at SUN Microsystems And CZJUG Co-Leader
http://blogs.sun.com/japod