users@jersey.java.net

Re: [Jersey] context resolver with package names ?

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Tue, 02 Mar 2010 09:56:36 +0100

Hi Felipe,

Do you have sub-packages? if so you may need to do:

   if (objectType.getPackage().getName().startsWith(PACKAGE)) {
     ...
   }

Paul.

On Feb 20, 2010, at 4:28 PM, Felipe Gaścho wrote:

> I tried to implement the context resolver using package names instead
> of class names, but it didn't worked. The JSON representation still
> with the JAXB format (with @ as attributes prefix)..
>
> * the same class using specific classes works, but I have hundreds of
> classes and it is boring to maintain the list
>
> @Provider
> public class MyJAXBContextResolver implements
> ContextResolver<JAXBContext> {
>
> private JAXBContext context;
> private final static String PACKAGE = PujAdvertisementEntity.class
> .getPackage().getName();
>
> public MyJAXBContextResolver() throws Exception {
> this.context = new
> JSONJAXBContext(JSONConfiguration.natural().build(),
> PACKAGE);
> }
>
> public JAXBContext getContext(Class<?> objectType) {
> return (PACKAGE.equals(objectType.getPackage().getName())) ? context
> : null;
> }
> }
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>