users@jersey.java.net

Re: custom serializer not getting called

From: jameskpublic <jameskpublic_at_yahoo.com>
Date: Thu, 16 Sep 2010 12:20:07 -0700 (PDT)

nm.
I was looking at the wrong example.
Just as a note, it's not at all clear from the docs that there are two
separate json processors that can be configured, nor is it clear which
classes and configs (context providers, FEATURE_POJO_MAPPING options and
such) go with each of the json processors. (e.g. Is JSONJAXBContext for
jackson?)
I was looking the jsonfromjaxb example all the while thinking it was jackson
when it wasn't.

For anyone else trying to do a jackson unit test on both the client and the
server, you have to configure the unit test to start the grizzley server in
jackson mode:

public class MainTest extends JerseyTest {

    public MainTest() {
        super(new WebAppDescriptor.Builder("javax.ws.rs.Application",
MyApplication.class.getName())
                .initParam(JSONConfiguration.FEATURE_POJO_MAPPING,
"true").build());
    }
...
}

but you also have to configure a client to do jackson serialization:

        @Override
        public void setUp() throws Exception {
                // TODO Auto-generated method stub
                super.setUp();
                
                ClientConfig cc = new DefaultClientConfig();
                cc.getClasses().add(JacksonJsonProvider.class);
                Client clientWithJacksonSerializer = Client.create(cc);
                resource = clientWithJacksonSerializer.resource(getBaseURI());
        }

It took me a while to put those two things together. :)
Hope that helps someone!
James

-- 
View this message in context: http://jersey.576304.n2.nabble.com/custom-serializer-not-getting-called-tp5534150p5540037.html
Sent from the Jersey mailing list archive at Nabble.com.