RESTEasy uses Jettison JSON library to map JAXB annotation object to and from JSON. In this tutorial, we show you how to convert an JAXB annotated object into JSON format and return it back to client.

Jackson as JSON provider
You may also interest to read this RESTEasy + Jackson example.

1. RESTEasy + JAXB + Jettison

To use JSON in RESTEasy, you need following dependencies.

File : pom.xml

		<id>JBoss repository</id>





2. JAXB XML Provider

Create an object, annotate with JAXB. Why using XML provider? No worry, later you will use @BadgerFish to convert it into JSON format.


import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

@XmlRootElement(name = "movie")
public class Movie {

	String name;
	String director;
	int year;

	public String getName() {
		return name;

	public void setName(String name) { = name;

	public String getDirector() {
		return director;

	public void setDirector(String director) {
		this.director = director;

	public int getYear() {
		return year;

	public void setYear(int year) {
		this.year = year;



To return a JSON file format, annotate the service method with @BadgerFish and @Produces("application/json").

RESTEasy will handle the JSON conversion automatically.

import org.jboss.resteasy.annotations.providers.jaxb.json.BadgerFish;

public class JSONService {

	public Movie getMovieInJSON() {

		Movie movie = new Movie();
		movie.setName("Transformers: Dark of the Moon");
		movie.setDirector("Michael Bay");
		return movie; 



4. Demo

When URI pattern “/json/movie/get” is requested, following JSON file will be returned.

			"$":"Michael Bay"
			"$":"Transformers: Dark of the Moon"

Download Source Code

Download it – (7 KB)


  1. Jettison Official Website
  2. JAXB Official Website
  3. RESTEasy JAXB Provider
  4. Downlaod XML file from JAX-RS