users@jersey.java.net

[Jersey] Re: Using Jackson for data binding with annotations

From: Tatu Saloranta <tsaloranta_at_gmail.com>
Date: Mon, 14 May 2012 12:17:24 -0700

On Mon, May 14, 2012 at 11:54 AM, <jdreux_at_justlexit.com> wrote:
> I am using Jersey over Tomcat on a project currently in production. I
> have been setting up my mapper as follows:
>
> public abstract class AbstractBusinessServices extends Application
> implements ContextResolver<JAXBContext>{
>
> ...
>
> public AbstractBusinessServices() {
>                try {
>                        this.types = this.getWebserviceModelClasses();
>                        this.context = new
> JSONJAXBContext(JSONConfiguration.natural().build(), types);
> ...
>
> }
>
> This has been working fine, but now we are hitting problem with JSON
> format that seem to be due to limitations of the JAXB parser. I want to
> use pure Jackson for marshalling and unmarshalling, and everywhere I
> look I see that I need to use this:
>
>
> <init-param>
>
> <param-name>com.sun.jersey.api.json.POJOMappingFeature</param-name>
>                <param-value>true</param-value>
>        </init-param>
>
> However I am using annotations everywhere, and I don't have a web.xml.
> What can I do to get this working with annotations?

Typically you just need MessageBodyReader/-Writer implementations, and
Jackson project provides "Jackson JAX-RS provider". That provider (of
said handlers) needs to be registered from
javax.ws.rs.core.Application implementation as far as I remember, and
you can create an instance or pass Class there.

Jackson Wiki has some links on:
http://wiki.fasterxml.com/JacksonFAQJaxRs although unfortunately not
specific code sample.

-+ Tatu +-