users@jersey.java.net

Re: [Jersey] XSL transform annotation and message body reader/writer

From: Robert Koberg <rob.koberg_at_gmail.com>
Date: Sun, 29 Nov 2009 08:33:15 -0800

On Nov 27, 2009, at 11:46 PM, Tatu Saloranta wrote:

> On Fri, Nov 27, 2009 at 7:16 AM, Robert Koberg <rob_at_koberg.com> wrote:
>> ufff... my mail client keeps choosing the wrong address to reply (more inline below)
>>
>>
>> On Nov 26, 2009, at 4:16 PM, Tatu Saloranta wrote:
>>
>>> On Tue, Nov 24, 2009 at 5:15 AM, Robert Koberg <rob_at_koberg.com> wrote:
>>>> Hi,
>>>>
>>> ...
>>>> I think that the message body writer would be the most useful as it can output pretty much anything. The main problem being is that it would not be as fast as directly streaming the result.
>>>
>>> How so? Message body readers and writers operate on streams, so this
>>> should not be a problem?
>>
>> First there is the jaxb parse to the object. Then you use javax.xml.bind.util.JAXBSource
>> for the transform. The XSL processor will parse that into an internal (optimized) DOM to operate on. In other words, you don't go straight to the output stream, but have an additional parse along the way.
>
> Right, if you do use data binding. But you don't have to do that:
> MessageBodyReaders and writer take InputStream/OutputStream, and it is
> up to implementation to do whatever it is to do. There is no automatic
> JAXB binding being done, it's just that default reader/writer
> implementations do that.
>
> So just pipe in stream into XSL processor, which will use whatever is
> fastest way (Saxon builds its own TinyTree, Xalan probably something
> similar).

That makes sense. So, as you read the stream of JSON events you emit the corresponding XML event. I remember discussing this a while ago on the Jackson list. Is there anything in Jackson that will make this process simple? :) Perhaps something like a JSONSource (implements javax.xml.transform.Source)?

thanks for your help,
-Rob