Pregunta

I'm converting my guice application to a spring based on because of issues I found with the @transaction annotation. When doing so, I came to a issue with the configuration of a custom objectmapper with spring/resteasy. I want to register the hibernate4Module (fasterxml jackson) and a custom deserializer.

I have found many solution when using spring mvc, but I'm not using spring mvc. I'm looking at the resteasyboostrap class, since there you have control over you factory, but I don't know how to register my new SimpleModule there.

Anyone with any experience? When I'm searching the internet, it seems nobody is trying to do the same thing. Perhaps I'm looking in the wrong places?

¿Fue útil?

Solución

This one was eventually an easy one to fix. Remove the resteasy-jackson provider and write a custom class that you annotate with the spring @Component annotation. Jax-RS picks up the provider and uses the object mapper in the provider. I was searching in the implementation, but the answer was in the jax-rs api.

@Component
@Provider
@Consumes({"application/*+json", "text/json"})
@Produces({"application/*+json", "text/json"})
public class JacksonProvider extends JacksonJsonProvider {
    public JacksonProvider() {
        setMapper(new CustomObjectMapper());
    }
}
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top