Hi
Well, this might be getting a bit involved for this forum, but if anyone has
any thoughts I would very much so appreciate hearing them.

I am close to getting the XsltJsonProvider working. I actually have it
working for writing, but I've run into a conceptual roadblock getting it to
work for reading.

I basically merged XsltJaxbProvider with JsonProvider (at least to get it
working), and in the marshalToOutputStream method I just passed in the
streamwriter for handling json.


        protected void marshalToOutputStream(Marshaller ms, Object obj,
                        OutputStream os, MediaType mt, XMLStreamWriter writer)
                        throws Exception {
                TransformerHandler th = 
factory.newTransformerHandler(createTemplates(
                                getOutTemplates(mt), outParamsMap, 
outProperties));
                // Result result = new StreamResult(os);
                Result result = new StaxResult(writer);
                if (systemId != null) {
                        result.setSystemId(systemId);
                }
                th.setResult(result);
                ms.marshal(obj, th);
        }

So the xslt is applied and then is written using jettison. Works great! :)

I'm actually not familiar enough with these API's to know for sure what is
going on in the marshal method, but my guess is that the Object is being
converted to xml with jaxb, the xslt is then applied, then it is written it
to the output stream using the jettison writer which converts the xml to
json as it is being written.

It is correct, yes.

If this is correct then the reverse, reading/unmarshaling, would first have
to convert the json to xml, apply the xslt, and then use jaxb to construct
the object. Unlike with writing though, I am not seeing a way to hand a
jettison reader and a filter to the unmarshaller all at once.'Plain' 
JAXBElementProvider and JSONProvider extend AbstractJAXBProvider.
I guess XSLT


I am trying something like the following (with multiple variations), to no
avail ...

XMLFilter filter = factory.newXMLFilter(createTemplates(
                getInTemplates(mt), inParamsMap, inProperties));

StaxSource source2 = new StaxSource(xsw); //where xsw is a XmlStreamReader
for handling json

response = unmarshaller.unmarshal(??);

Unlike with marshaling I am just not seeing a way to get those two concepts
together. Is there not a way to do this in one step, and so I should
manually convert the json to xml first? Am I misunderstanding how this whole
thing works?

Again, I can provide more code if it would be useful, and any insight is
greatly appreciated. :)

Have a look at XSLTJaxbProvider. At the moment, the reader is copied to CashedOutputStream and only then the template is applied to the InputStream obtained from the cashed output stream. May be there's even a more effective way to achieve the transformation.
Let us know please if that approach works for you

Cheers, Sergey

-Bob




--
View this message in context: 
http://cxf.547215.n5.nabble.com/XSLTJaxbProvider-and-json-tp4632954p4637126.html
Sent from the cxf-dev mailing list archive at Nabble.com.

Reply via email to