Reputation: 51
Does jibx support json? or is there a way to support json format using jibx marshalling? I am trying to implement a rest service with json format support and alsi jibx marshalling support.
Upvotes: 1
Views: 652
Reputation: 216
It's possible to generate JSON with JiBX by using Jettison:
StringWriter pw = new StringWriter(16384);
XMLStreamWriter w = new MappedXMLStreamWriter(mnc, pw);
// Generate XML.
IMarshallingContext mctx = bfact.createMarshallingContext();
mctx.setXmlWriter(
new StAXWriter(bfact.getNamespaces(), w));
w.writeStartDocument();
mctx.marshalDocument(obj, "UTF-8", true);
w.writeEndDocument();
w.close();
pw.close();
return pw.toString();
However, all of the XML attributes will come out as strings.
Upvotes: 1
Reputation: 496
Sorry, JiBX does not support json marshalling/unmarshalling.
I would suggest using JiBX for the XML part and take a look at this stackoverflow subject for converting dom to json.
Don
Upvotes: 1