users@jersey.java.net

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

From: Joseph Mocker <jmocker_at_velti.com>
Date: Thu, 28 Mar 2013 22:24:40 +0000

But does the constructor get called? Just not getContext()? Have you maybe accidentally enabled Jackson/JSON POJO mapping instead of JAXB?

  --joe


[Velti]<http://www.velti.com> Joseph Mocker | Senior Software Architect
t +1.650.566.7033 m
e jmocker@velti.com @Mobclix<http://twitter.com/Mobclix>
[cid:sep1111189e17d]
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<mailto: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<tel:%2B1.650.566.7033> m
e jmocker_at_velti.com<mailto: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<mailto:brian_at_gabey.com>>
 <brian_at_gabey.com<mailto: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;
> }
> }






logo11111e0cbea
(image/gif attachment: logo11111e0cbea)

sep1111189e17d
(image/gif attachment: sep1111189e17d)