users@jersey.java.net

JSON (possible JAXB?) strangeness

From: Zoltan Arnold NAGY <Zoltan.Nagy_at_Sun.COM>
Date: Thu, 08 Oct 2009 14:46:09 +0200

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