To return data from the Restaasy resource method, you need to do a few things depending on what you are trying to return.
You need to annotate your resource method using the @Produces annotation to tell Resteasy what the return type should be.
For example, the following method returns XML and JSON depending on what the client requests in its Accept header.
@GET @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) public Response foo() { PersonObj obj = new PersonObj();
Restaasy supports sorting of the following data types by default:

If the data types you want to support are in this table, then it means that they are supported by JAXB, and all you have to do is annotate your PersonObj class with JAXB annotations to tell you how the marshall and unmarshall object are.
@XmlRootElement @XmlType(propOrder = {"firstName", "lastName"}) public class PersonObj { private String firstName; private String lastName;
What if your content type is not supported out of the box?
If you have a custom content type that you want to customize, you need to create a MessageBodyWriter implementation that tells Resteasy how to set up the token.
Provider @Produces({"application/x-mycustomtype"}) public class MyCustomTypeMessageBodyWriter implements MessageBodyWriter { }
Just implement the interface and register it like any other provider.
If you want to read a custom content type, you need to implement a custom MessageBodyReader to process the incoming type and add it to the @Consumes annotation @Consumes to your receiving method.
source share