users@jersey.java.net

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

From: Chase <chase_at_osdev.org>
Date: Thu, 28 Mar 2013 17:46:57 -0500

Do you have the @Provider annotation on the class?

In my environment I never could get mine to be automatically discovered, I
had to have an Application subclass that was configured and returned my
JAXBContext provider from the getSingletons() method.

On Thu, Mar 28, 2013 at 4:11 PM, <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;
> }
> }
>