users@jersey.java.net

Re: [Jersey] JSON Format

From: Jakub Podlesak <Jakub.Podlesak_at_Sun.COM>
Date: Tue, 14 Oct 2008 13:32:17 +0200

Hi Lars,

On Tue, Oct 14, 2008 at 11:47:35AM +0200, Lars Tackmann wrote:
> Hi all
>
> Consider the following XML (showing a empty, single and multi element
> user list).
>
> --
> # empty user list
> <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
> <users/>
>
> # single element user list
> <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
> <users>
> <user>
> <id>1</id>
> <name>user1</name>
> </user>
> </users>
>
> # multi element user list
> <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
> <users>
> <user>
> <id>2</id>
> <name>user2</name>
> </user>
> <user>
> <id>1</id>
> <name>user1</name>
> </user>
> </users>
> --
>
> Prior to Jersey 1.0 this used to be converted into the following JSON code:
> --
> # empty user list
> {"users":null}
>
> # single element user list
> {"users":{"user":[{"id":"1","name":"user1"}]}}

For this you configured user to be treated as an array, right?
I am wondering if the configuration remains same for your app using the 1.0 version.
The way to configure things has changed, but the old way should remain
supported.

New way for configuring the json array property:

props.put(JSONJAXBContext.JSON_ARRAYS, new HashSet<String>(1){{add("user");}});


>
> # multi element user list
> {"users":{"user":[{"id":"2","name":"user2"},{"id":"1","name":"user1"}]}}
> --
>
> but in 1.0 it now gets converted into:
> --
> # empty user list
> null
>
> # single element user list
> {"user":{"id":"1","name":"user1"}}

The brackets are missing here (mentioned above)

>
> # multi element user list
> {"user":[{"id":"2","name":"user2"},{"id":"1","name":"user1"}]}
> --
>
> is this by design ? (and is this new format stable). If so then I will

Yes, the root element is stripped off by default at all cases,
if user does not configure otherwise. It should be stable for the upcoming releases.

It was actually a bug in the previous releases, where the stripping feature
was not consistently set on by default for all cases.

For further releases, you could also expect better integration with JAXB RI,
where the above mentioned configuration should not be needed any more.
(should become available when JAXB 2.1.10 is released)

~Jakub

> refactor my client code to deal with it,
> if not then perhaps I should apply a provider fix.


>
>
> --
> Yours sincerely
>
> Lars Tackmann
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>

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