users@jersey.java.net

[Jersey] Glassfish, Jersey and JSON

From: John Lister <john.lister_at_kickstone.co.uk>
Date: Sun, 28 Feb 2010 21:43:42 +0000

Hi, I've worked it out, my other question prompted a reread of your blog and in a slightly less sleep deprived state (just had twins) I noticed that the provider class needs to be in the same package as the resource files.

Thanks

John
Felipe Gaścho <fgaucho_at_gmail.com> wrote:

>you have an array of 2 types but only check for the index 0 ?
>
>I tried to use the package name instead of specific classes but I
>didn't get success..
>
>On Sun, Feb 28, 2010 at 3:52 PM, John Lister <john.lister_at_kickstone.com> wrote:
>> Hi, using glassfish V3 and Jersey 1.4.1 and I'm playing with the JSON
>> support which is where I've got 2 questions:
>> I'm trying to use the natural notation and struggling to get it to work,
>> I've followed the many examples on the web and created a Provider class that
>> implements ContextResolver as follows:
>>
>> @Provider
>> public class MyJAXBContextResolver implements ContextResolver<JAXBContext>
>> {
>>
>> private JAXBContext context;
>> private Class[] types = {MyBean.1class, MyBean2.class};
>>
>> public MyJAXBContextResolver() throws Exception {
>> this.context = new JSONJAXBContext(
>> JSONConfiguration.mapped()
>> .rootUnwrapping(true)
>> .arrays("arrayVar")
>> .nonStrings("number1", "number2")
>> .build(),
>> types);
>> }
>>
>> public JAXBContext getContext(Class<?>> objectType) {
>> return (types[0].equals(objectType)) ? context : null;
>> }
>> }
>>
>>
>> but it doesn't get picked up by glassfish, The logs just show
>> INFO: Providers classes found:
>> after my resources are found which concludes me to believe the provider
>> class hasn't been picked up.
>> Have missed something somewhere or does this not work with glassfish...
>>
>>
>> Secondly is it possible through some form of configuration to specify the
>> natural notation as the default or at least set it for all classes, at the
>> minute it seems I have to list all classes I want it to be applied to (which
>> is every class in my project) which has the potential to cause problems in
>> the future if I forget to update the list when a new data class is added.