users@jersey.java.net

Re: [Jersey] using jaxb to stream a large data set

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Tue, 09 Feb 2010 18:05:43 +0100

On Feb 9, 2010, at 1:15 AM, Moiz Dohadwala wrote:

> Hello,
>
> We am currently using jersey to build a set of reports. The reports
> on the UI are paginated, since the data set can potentially be very
> large. However, we need to provide a download option to allow the
> user to download the entire set. Currently we have been using jaxb
> to provide support for xml as well as json. What options to we have
> to support streaming streaming using jaxb in jersey?
>

JAXB is not a streaming-based API so i guess any approach would be to
utilize "fragments" of JAXB.

The only current support for fragments of JAXB is returning a List<T>
or Collection<T> (and it would be really easy to extend to support
Iterator<T>).

You could implement a Collection that supports a lazy iterator.

Alternatively you could implement the JAXB fragment marshaling
yourself using StreamingOutput [1].

Paul.

[1] https://jsr311.dev.java.net/nonav/javadoc/javax/ws/rs/core/StreamingOutput.html