users@jersey.java.net

[Jersey] Re: Not able to customize the JSON encoding ....

From: Brian Mason <brian_at_gabey.com>
Date: Thu, 28 Mar 2013 16:06:56 -0700

Nothing was getting called, but I figured it out. My Application class was
being referenced for resrouces and it was not in the resource list.
I though the package servlet param would do the trick but it appears to be
needed in the Application classes resource list.

Thanks!!

On Thu, Mar 28, 2013 at 3:24 PM, Joseph Mocker <jmocker_at_velti.com> wrote:

> But does the constructor get called? Just not getContext()? Have you
> maybe accidentally enabled Jackson/JSON POJO mapping instead of JAXB?
>
> --joe
>
> [image: Velti] <http://www.velti.com> *Joseph Mocker *| Senior
> Software Architect
> *t* +1.650.566.7033 *m*
> *e* jmocker_at_velti.com
> @Mobclix <http://twitter.com/Mobclix>
>
> The leading global technology provider of
>
> mobile marketing and advertising solutions
>
> <http://mwc.velti.com/meet-us>
>
>
> On Mar 28, 2013, at 3:06 PM, Brian Mason wrote:
>
> I am not using spring. But I am using the jersey servlet and I have
> specified the package where the path endpoints are and my one provider.
> The paths are pi Med up. Just not the provider.
>
> Thanks
> Brian
> On Mar 28, 2013 3:01 PM, "Joseph Mocker" <jmocker_at_velti.com> wrote:
>
>> Maybe your ContextResolver is not being picked up by Jersey. For example
>> if you are using the spring-jersey integration you probably have to include
>> the parameter "com.sun.jersey.config.property.packages" in your web.xml
>> file to tell jersey to scan specific packages for providers, etc.
>>
>> --joe
>>
>>
>> Joseph Mocker | Velti | Senior Software Architect
>> t +1.650.566.7033 m
>> e jmocker_at_velti.com @Mobclix
>>
>> The leading global technology provider of
>> mobile marketing and advertising solutions
>>
>> On Mar 28, 2013, at 2:11 PM, <brian_at_gabey.com>
>> <brian_at_gabey.com> wrote:
>>
>> > I followed the example in the users guide for adding a ContextResolver
>> > so I can pick the JSON encoding style.
>> > The getContext method is never called on my class.
>> > It is in the package with the Path Endpoints (Which are picked up
>> > fine).
>> > I am very confused and any help would be nice.
>> >
>> > Thanks,
>> > Brian
>> > Example code
>> > public class JAXBContextResolver implements
>> > ContextResolver<JAXBContext> {
>> >
>> > private JAXBContext context;
>> > private Set<Class> types;
>> > private Class[] clss =
>> > {StorageSystemListResponse.class,StorageSystemResponse.class};
>> >
>> > public JAXBContextResolver() throws Exception {
>> > types=new HashSet<>(Arrays.asList(clss));
>> > System.out.println("************************** IN JAXB
>> > 1**************************************");
>> > System.err.println("************************** IN JAXB
>> > 1**************************************");
>> > this.context = new
>> > JSONJAXBContext(JSONConfiguration.badgerFish().build(),clss);
>> > }
>> > public JAXBContext getContext(Class<?> objectType) {
>> > System.out.println("************************** IN JAXB
>> > 2**************************************");
>> > System.err.println("************************** IN JAXB
>> > 2**************************************");
>> >
>> > return (types.contains(objectType)) ? context : null;
>> > }
>> > }
>>
>>
>