Configuring JAXB Mapping On A JAX-RS 2.0 Client

Mapping of POJOs to XML needs to be configured on a JAX-RS 2.0 client with registering a feature class:

import org.glassfish.jersey.jackson.JacksonFeature;
import org.junit.Before;
import org.junit.Test;

public class MessagesResourceIT {

    private Client client;
    private WebTarget messagesTarget;

    public void initClient() {
        this.client = ClientBuilder.newClient().register(JacksonFeature.class);
        this.messagesTarget ="http://.../");

    public void allMessages() {
        Message response = this.messagesTarget.path("42").request().get(Message.class);
		//...asserts omitted

In addition you will also have to setup the dependency to the underlying framework (Jackson in this case):


JavaEE 7 JSON processing needs similar configuration as well.

See you at Java EE Workshops at MUC Airport!


I suppose there's an error in the title. It should be Jackson/JSON, rather than JAXB.

Posted by Matt Bukowicz on July 10, 2013 at 12:25 AM CEST #

Post a Comment:
  • HTML Syntax: NOT allowed
...the last 150 posts
...the last 10 comments