users@jersey.java.net

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

From: Markus Karg <markus.karg_at_gmx.net>
Date: Wed, 24 Feb 2010 17:51:17 +0100

Hello Oscar,

they key to other return types are "MessageBodyWriters": Declare any typed
you want, JAX-RS will handle them all. But not out of the box: In short, out
of the box you will get Strings (returned als plain text) and JAXB Elements
(returned as XML) (plus a bit more stuff like JSON and so on), and
OutputStream. If you want to use "any" Object type or "any" kind of MIME
entity, you need to register a "conversion" object (i. e.
"MessageBodyWriter"). See here:
http://java.sun.com/javaee/6/docs/tutorial/doc/gilik.html#gipze

HTH
Markus

> -----Original Message-----
> From: Oscar Calderon [mailto:oscar.kalderon_at_gmail.com]
> Sent: Mittwoch, 24. Februar 2010 17:10
> To: users_at_jersey.dev.java.net
> Subject: [Jersey] RESTful WS: How to return something different than
> String?
>
> Hi to all, i'm a newbie in RESTful web services. I've worked before
> with
> normal web services and i have a doubt about sending/receiving data
> with
> service. Somebody knows something like a guide to explain how to return
> something different than a String from RESTful web service resource?
> For
> example return a stream, a list or something like that? That's because
> i've developed some simple RESTful web services that returns only a
> string, for example a XML string or JSON String, but i haven't found
> documentation or something like "How to receive a list as parameter" or
> "How to return a stream" or something like that.
>
> Somebody has an idea about some tutorial or documentation to learn
> that?
>
> Thanks in advance.
>
> --
> Oscar Calderon
>
> JAVA Tutorials and How to's? Visit http://www.javahowto.net/
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net