users@jersey.java.net

Re: strange JSON serialization

From: Jakub Podlesak <Jakub.Podlesak_at_Sun.COM>
Date: Tue, 08 Jan 2008 15:11:43 +0100

Hi Akos,

On Mon, Jan 07, 2008 at 04:30:54PM +0100, Ákos Maróy wrote:
> Jakub,
>
> > For jaxb beans, badgerfish notation [1] is used, which is what you see.
> > If you want something simpler you need to use JSONObject/JSONArray
> > instead of jaxb bean.
> >
> > I am working on improving json generated from jaxb, but it is not likely
> > the whole thing will be ready for 0.5 release.
> >
> > Jersey currently uses jettison project for json support.
> > Given that jettison provides two options for produced json notation,
> > i can imagine we can quickly provide a switch to get the other (Mapped Convention)
> > notation (see [3]). Will it work for you?
>
> Yes, I guess this is what I was looking for..
>
> Would be fabulous to have such a switch in 0.5..

I am sorry, i was promising too quickly.
It turns out that implementing the switch would
be difficult since it would need changes in certain
basic JSR-311 interfaces.

The good news is that JSR-311 is going to include
context resolver mechanism for MessageBodyReader/Writer in
version 0.6 as a mean to pass parameters to particular
entity readers/writers. At that time json support should
be integrated to jaxb, and so you will be able to use
other json notatioins.

If you want to experiment with the mapped notation in the meantime,
you might want to build up jersey from source code after making following changes
in [com.sun.ws.rest.impl.provider.entity.JSONJAXBElementProvider]:

1. in [readFrom] method: instead of:
                    return unmarshaller.unmarshal(
                            new BadgerFishXMLStreamReader(
                            new JSONObject(readFromAsString(entityStream))));
   insert:
                    return unmarshaller.unmarshal(
                            new MappedXMLStreamReader(
                            new JSONObject(readFromAsString(entityStream))));
2. in [writeTo] method: instead of:
                    marshaller.marshal(t,
                            new BadgerFishXMLStreamWriter(
                            new OutputStreamWriter(entityStream)));
   insert:
                    marshaller.marshal(t,
                            new MappedXMLStreamWriter(new MappedNamespaceConvention(),
                            new OutputStreamWriter(entityStream)));

Thanks for understanding,

~Jakub

>
>
> Akos
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>

-- 
Jakub Podlesak
http://blogs.sun.com/japod