views:

826

answers:

1

So I am writing a Spring(2.5( + Jersey(1.1.4.1) and trying to create a JSONConfiguration using a ContextResolver. Here is the code:

package com.rhigdon.jersey.config;

import com.sun.jersey.api.json.JSONConfiguration;
import com.sun.jersey.api.json.JSONJAXBContext;

import javax.ws.rs.ext.ContextResolver;
import javax.ws.rs.ext.Provider;
import javax.xml.bind.JAXBContext;

@Provider
public final class JAXBContextResolver implements ContextResolver<JAXBContext> {
  private JAXBContext context;

  public JAXBContextResolver() throws Exception {
    this.context = new JSONJAXBContext(JSONConfiguration.mappedJettison().build(), "com.rhigdon.core.model.");
  }

  public JAXBContext getContext(Class<?> aClass) {
    return context;
  }
}

Unfortunately my app is still returning the default mapping:

{"id":"1","question":"What is/was the name of your first pet?"}

When I debug the application it never actually hits this code. Is this due to using the SpringServlet? Here is my Jersey Config in my web.xml:

<servlet>
    <servlet-name>Jersey Spring Web Application</servlet-name>
    <servlet-class>com.sun.jersey.spi.spring.container.servlet.SpringServlet</servlet-class>
</servlet>
<servlet-mapping>
    <servlet-name>Jersey Spring Web Application</servlet-name>
    <url-pattern>/*</url-pattern>
</servlet-mapping>

Anyone have a similar setup with JSONConfiguration working?

+1  A: 

You need to register your provider in your spring context:

<bean class="com.redoption.jersey.config.JAXBContextResolver"/>
rhigdon
This was a pretty obvious solution but I wanted to answer in case anyone else had a mind blank like me. :)
rhigdon