Re: [Jersey] RESTful WS: How to return something different than String?

From: Craig McClanahan <>
Date: Thu, 25 Feb 2010 09:26:17 -0800

On Thu, Feb 25, 2010 at 7:00 AM, Oscar Calderon
<> wrote:
> I was reading about this, but it's a little bit confuse for me, but i
> understood that first, if i have an object that i want to serialize
> (example, a Employee class) i have to build my EmployeeProvider , a class
> that implements MessageBodyWriter<Employee> then implement the 3 methods.
> After that, i guess that i have to use that class in my resource class. I've
> seen that the method must return a Response object right? I've download
> Jersey sample applications, somebody knows if one of that applications has a
> concrete example about how to use MessageBodyWriter (building and using
> custom providers or using out of the box providers)?

The information you've been given about custom MessageBodyWriter (and
MessageBodyReader to process the bodies of incoming requests) is
correct. But don't forget that you can get the serialization "for
free" if you annotate your Java classes with the appropriate JAXB
annotations like @XmlType. For such a Java class, the JAX-RS will
provide the appropriate MessageBodyWriter and MessageBodyReader
classes automatically.

There are examples of this in the "samples" directory as well.

Craig McClanahan