users@jersey.java.net

Re: [Jersey] JSON Arrays

From: Jakub Podlesak <Jakub.Podlesak_at_Sun.COM>
Date: Thu, 24 Jul 2008 14:54:17 +0200

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).

Copy&pasted from Paul's blog [1]:

ClientConfig cc = new DefaultClientConfig();
cc.getProviderClasses().add(PropertiesProvider.class);

It is a great news you fixed the issue. Can you please share more details on it?

Thanks,

~Jakub


[1]http://blogs.sun.com/sandoz/entry/jersey_client_api



On Wed, Jul 23, 2008 at 10:57:36PM +0200, Lars Tackmann wrote:
> Hi
>
> I have implemented the jersey fix for missing brackets in JSON arrays
> (http://blogs.sun.com/japod/entry/missing_brackets_at_json_one) to
> great satisfaction for the people hacking on our AJAX rest front end.
> However my tests which uses the jersey client are now failing, i.e.
> the code:
> --
> assertThat(Status.fromStatusCode(cr.getStatus()), equalTo(Status.OK));
> CountryBeanList list = cr.getEntity(CountryBeanList.class);
> --
>
> results in:
> --
> java.lang.ClassCastException: com.example.CountryBean cannot be cast
> to com.example.CountryBeanList
> at com.example.test.ResourceTest.countryListTest(ResourceTest.java:47)
> --
>
> the JSON code produced when it fails looks like this:
> --
> {"country":[{"name":"Denmark","countryCode":"DK"},{"name":"Finland","countryCode":"FI"}]}
> --
>
> however when leaving out the modified @Provider it looks like this
> --
> {"countries":{"country":[{"name":"Denmark","countryCode":"DK"},{"name":"Finland","countryCode":"FI"}]}}
> --
>
> This code can be correctly converted/tested (note the root "countries"
> type). Could it be that since both CountryBean and CountryBeanList are
> root elements (@XmlRootElement), the JSON provider no longer works
> (when modified to handle brackets correctly) ?. Any
> ideas/comments/solutions to this annoyance are most welcome.
>
>
> --
> 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