[Jersey] How to make a JSONConfiguration

From: Pengfei Di <>
Date: Wed, 6 Apr 2011 13:28:19 +0200

Hello Group,

I am trying to turn off the rootUnwrapping feature by specifying a
JSONConfiguration. (In other words: I'd like to add the class name into
the JSON string.)
Although I added a JAXBContextResolver (from Example 5.6 of the Jersey
Guide) into my project, the new JSONConfiguration seems not to take effect.
What I found is that, the constructor method of JAXBContextResolver has
been called once, but the getContext method has never been called, no
matter how many responses are generated.

Shouldn't the getContext method be called?
Did I forget something?

Thanks a lot for any hint.


The source code of the JAXBContextResolver is following:

public class JAXBContextResolver implements ContextResolver<JAXBContext> {
     private JAXBContext context;
     private Class[] types = { MyClass1.class, MyClass2.class };

     public JAXBContextResolver() throws Exception {
         JSONConfiguration config =
         this.context = new JSONJAXBContext(config, this.types);

     public JAXBContext getContext(Class<?> objectType) {
         System.out.println(" --------- This sentence never apprears!
         for (Class<?> type : this.types) {
             if (type == objectType) {
                 return this.context;
         return null;