users@jersey.java.net

JSON processing <was>Re: IRC Chat: Paul Sandoz and Frank Martinez (Declarative Security, Injectables) Fragment.

From: Jakub Podlesak <Jakub.Podlesak_at_Sun.COM>
Date: Fri, 11 Apr 2008 17:47:50 +0200

On Thu, Apr 10, 2008 at 01:09:42PM -0500, Frank Martínez wrote:
> > At the JAXB->JSON approach: was the only issue the one-elem array thing?
> > Or is there something else to improve/change?
> >
>
> one-element array and generic collection in generic classes like this:
>
> class XXX<T> {
> private List<T> yyy;
> }

Here JAXB puts some type information into the generated XML.
E.g. for XXX<String>:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<listWrapper>
  <items xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema" xsi:type="xs:string">one</items>
  <items xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema" xsi:type="xs:string">two</items>
</listWrapper>

So the JAXB->(simple)JSON way seems indeed a bit complicated here :-(

>
> > Besides JAXB beans (@XmlRootElement annotated POJOs) related readers/writers
> > there were some other approaches considered/discussed as well:
> >
> > i) POJO<->JSON readers/writers (maybe POJOs with JSON specific annotations
> > (json-lib way))
> > ii) POJO<->JSON readers/writers when serialization/deserialization is being done
> > via JAXB->JSON mapping (current mechanism) leveraging the possibility
> > in JAXB2 to marshal/unmarshall raw (unannotated) POJO by wrapping
> > it with JAXBElement object.
> >
> > Do you think that one of them should be somehow included in Jersey?
> >
> > What do others think?
> >
>
> I prefer the option (i) but supporting unannotated POJOs too.
> So you can have a POJO with JAXB annotations but it will be serialized
> via JAXB only if the ProduceMime is application/xml. It is serialized
> via JSON reader/writer if ProduceMime is application/json.

I agree that Jersey should support unnanotated POJO<->JSON case.

I still think that the JAXB way could be improved, so that there is no need
to workaround it or choose something very different. Anyway, the above mentioned generic
case shows it could be difficult. I will see what outcome i have
from discussion with JAXB guys, which will happen at JavaOne.

~Jakub


>
> > Thanks,
> >
> > ~Jakub
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> > For additional commands, e-mail: users-help_at_jersey.dev.java.net
> >
> >
>
> Cheers,
> Frank.
>
> --
> Frank D. Martínez M.
> Asimov Technologies Ltda.
> Blog: http://www.ibstaff.net/fmartinez/
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>