users@jersey.java.net

Re: [Jersey] Glassfish, Jersey and JSON

From: John Lister <john.lister_at_kickstone.com>
Date: Sun, 28 Feb 2010 21:04:11 +0000

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

Thanks for you quick reply.

Sorry cut and paste problem. I took one of the web examples and modified it which mirrors mine
except for the errors you highlighted..

My problem is that the class never seems to be created or used. Putting breakpoints or logging in
either the constructor or the methods indicates none are being called. Have I missed something
in glassfish or the project config to get this class loaded? I haven't modified any other part of the
project apart from adding the context resolver class.

Thanks


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