users@jersey.java.net

context resolver with package names ?

From: Felipe Gaścho <fgaucho_at_gmail.com>
Date: Sat, 20 Feb 2010 16:28:58 +0100

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;
        }
}