Hi Lars,
please see bellow...
On Wed, Jul 30, 2008 at 02:51:53PM +0200, Lars Tackmann wrote:
> On Thu, Jul 24, 2008 at 2:59 PM, Paul Sandoz <Paul.Sandoz_at_sun.com> wrote:
> > Jakub Podlesak wrote:
> >>
> >> Hi Lars,
> >>
> >> Have you tried to register your provider on the client side as well?
> >> I think you need to make it manually (it won't be picked up automatically,
> >> but maybe i am mistaken).
> >>
> >
> > You are correct, scanning is not performed on the client side for providers.
>
> Adding the provider does fix the unit tests but it does not fix the
> underlying problem of the crippled JSON conversion:
>
> Consider the following unit test:
> ----
> @Test
> public void arrayTest() {
> final int[] numbers = { 0, 1, 2 };
> final String[] mediaTypes = { MediaType.APPLICATION_JSON,
> MediaType.APPLICATION_XML };
> for (String mediaType : mediaTypes) {
> for (int n : numbers) {
> WebResource resource = getResource(String.format(
> "json?number=%s", n));
> Builder builder = resource.accept(mediaType);
> String response = builder.get(String.class);
> System.out.println(response);
> }
> }
> }
> ----
>
> which tests the following resource:
> ----
> @GET
> @ProduceMime( { MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
> public UserBeanList getUsers(@QueryParam("number") Integer number) {
> UserBeanList users = new UserBeanList();
> while (number > 0) {
> UserBean userBean = new UserBean();
> userBean.setId((long) number);
> userBean.setName("user" + number);
> users.getUsers().add(userBean);
> number--;
> }
> return users;
> }
> ----
>
> Where UserBean and UserBeanList is generated from this XML model:
> -----
> http://svn.randompage.org/java/samples/jax-rs/spring/src/main/jaxb/model.xsd
> http://svn.randompage.org/java/samples/jax-rs/spring/src/main/jaxb/bindings.xml
> -----
>
> you would expect the following output:
>
> ----
> {"users":null}
> {"users":{"user":[{"id":"1","name":"user1"}]}}
> {"users":{"user":[{"id":"2","name":"user2"},{"id":"1","name":"user1"}]}}
> <users/>
> <users><user><id>1</id><name>user1</name></user></users>
> <users><user><id>2</id><name>user2</name></user><user><id>1</id><name>user1</name></user></users>
> ----
>
> however with the array fix you get:
> ----
> null
> {"user":{"id":"1","name":"user1"}}
> {"user":[{"id":"2","name":"user2"},{"id":"1","name":"user1"}]}
> <users/>
> <users><user><id>1</id><name>user1</name></user></users>
> <users><user><id>2</id><name>user2</name></user><user><id>1</id><name>user1</name></user></users>
> ----
>
> if I remove the array fix then I get the correct "users" prefix, but
> no brackets:
what if you left the fix in and just added another property to your custom
context resolver:
props.put(JSONJAXBContext.JSON_ROOT_UNWRAPPING, Boolean.FALSE);
Does it work?
There is probably a bug in the marshalling, where by default i wanted
a simplified format without the "users" prefix. Current behaviour is inconsistent.
I will look at it and fix it before 0.9.
Thanks for your patience and for letting us know there is an issue!
~Jakub
> ----
> {"users":null}
> {"users":{"user":{"id":"1","name":"user1"}}}
> {"users":{"user":[{"id":"2","name":"user2"},{"id":"1","name":"user1"}]}}
> <users/>
> <users><user><id>1</id><name>user1</name></user></users>
> <users><user><id>2</id><name>user2</name></user><user><id>1</id><name>user1</name></user></users>
> ----
>
> This is quickly turning into a major problem for me since I cannot
> present my AJAX programmers with a stable logical JSON interface.
> Either they have to hack around missing brackets or they will have to
> deal with missing type information. Any help will be greatly
> appreciated.
>
> --
> 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