Viewed 7791 times

JSON with JAXB - Jackson

I wondered how various RESTful implementations (like RESTeasy) use JAXB annotations to create JSON output. The Answer is Jackson - see Using JAXB annotations with Jackson.

In a short:

Maven deps:

<!-- Jackson -->

And a simple test:

package cz.zizka.ondra.jacksontest;

import java.io.IOException;
import javax.xml.bind.annotation.XmlRootElement;
import org.codehaus.jackson.map.AnnotationIntrospector;
import org.codehaus.jackson.map.ObjectMapper;
import org.codehaus.jackson.xc.JaxbAnnotationIntrospector;

 * @author Ondrej Zizka
public class JacksonTest extends TtdTestBase {

  public void testJackson() throws IOException
    ObjectMapper mapper = new ObjectMapper();
    AnnotationIntrospector introspector = new JaxbAnnotationIntrospector();
    // make deserializer use JAXB annotations (only)
    // make serializer use JAXB annotations (only)

    mapper.writeValue( System.out, new Car("Red Devil") );

}// class JacksonTest

class Car {
  public String name;

  public Car( String name ) {
    this.name = name;

Nice, simple, easy. Enjoy!

Wicket 6.9.0 Inspector Session: 2.5K Page: 12.2K Remove