users@jersey.java.net

Re: [Jersey] JSON (possible JAXB?) strangeness

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Thu, 08 Oct 2009 15:01:37 +0200

Hi Zoltan,

Your problem is here:

        public JAXBContext getContext(Class<?> objectType) {
            return (types[0].equals(objectType)) ? context : null;
        }

You are only using the JSONJAXBContext for the first element in the
types array, thus the second item in the array never uses that context
when serialized out as an representation.

Paul.

On Oct 8, 2009, at 2:46 PM, Zoltan Arnold NAGY wrote:

> Hey all,
>
> please see the code here: http://nagyz.pastebin.com/m323e406b
>
> I'm running it with latest JAXB (2.1.12), and latest Jersey (1.1.2-
> ea).
> The JAXBContextResolver code comes from Japod's blog
> (http://blogs.sun.com/japod/entry/configuring_json_for_restful_web)
>
> now, if I fetch http://localhost:4343, I get:
> {"a":[{"id":"10","blist":[{"value":"0"},{"value":"0"}]},
> {"id":"11","blist":[{"value":"0"},{"value":"1"}]}]}
>
> and if I fetch http://localhost:4343/1, I get:
> [{"value":0},{"value":1}]
>
> and then here's the catch: if we reverse the classes' order in the
> List (so declaring it like
> private Class[] types = { A.class, B.class }), we do get a very
> different JSON back, namely:
>
> http://localhost:4343 will give back:
> [{"id":10,"blist":[{"value":0},{"value":0}]},{"id":11,"blist":
> [{"value":0},{"value":1}]}]
>
> and http://localhost:4343/1 will give back:
> {"b":[{"value":"0"},{"value":"1"}]}
>
> Is this to be expected?
> If it is, why?
>
> I just spend half an hour hunting this behaviour.. :)
>
> Thanks,
> Zoltan
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>