users@jersey.java.net

[Jersey] Re: Pluggable StAX message body writers as streaming alternative to JAXB POJO's?

From: Tatu Saloranta <tsaloranta_at_gmail.com>
Date: Thu, 24 Mar 2011 15:48:55 -0700

On Thu, Mar 24, 2011 at 1:08 AM, Casper Bang <casper.bang_at_gmail.com> wrote:
> Hi Jacub,
> I am not familiar with XMLStreamWriter, but if this would allow for
> streaming XML/JSON etc. then I guess that's what I mean. :)
> /Casper

Stax API is for XML; although some libraries like Jettison (ab)use it
to produce kind of JSON.
But it is not a general way to produce formats other than XML; I can't
think of a Java API that does this.
Rather, use of POJOs allows somewhat seamless production of different
formats using appropriate backends.

So in that sense, ability to use streaming is currently a data-format
specific thing.
I am not sure JAX-RS or Jersey should try to standardize on this,
given that there is no way to make it really generic.

For output it is actually easy to do streaming output, by using
StreamingOutput wrapper, which gets invoked by Jersey, with
OutputStream to send output to.
For input side there isn't equivalent abstraction (due to mapping
needs), so MessageBodyReader impl is needed.

-+ Tatu +-