use of org.codehaus.jettison.util.StringIndenter in project cxf by apache.
the class JSONProvider method marshal.
protected void marshal(Marshaller ms, Object actualObject, Class<?> actualClass, Type genericType, String enc, OutputStream os, boolean isCollection) throws Exception {
OutputStream actualOs = os;
MessageContext mc = getContext();
if (mc != null && PropertyUtils.isTrue(mc.get(Marshaller.JAXB_FORMATTED_OUTPUT))) {
actualOs = new CachedOutputStream();
}
XMLStreamWriter writer = createWriter(actualObject, actualClass, genericType, enc, actualOs, isCollection);
if (namespaceMap.size() > 1 || namespaceMap.size() == 1 && !namespaceMap.containsKey(JSONUtils.XSI_URI)) {
setNamespaceMapper(ms, namespaceMap);
}
org.apache.cxf.common.jaxb.JAXBUtils.setNoEscapeHandler(ms);
ms.marshal(actualObject, writer);
writer.close();
if (os != actualOs) {
StringIndenter formatter = new StringIndenter(IOUtils.newStringFromBytes(((CachedOutputStream) actualOs).getBytes()));
Writer outWriter = new OutputStreamWriter(os, enc);
IOUtils.copy(new StringReader(formatter.result()), outWriter, 2048);
outWriter.close();
}
}
use of org.codehaus.jettison.util.StringIndenter in project tomee by apache.
the class AbstractCommand method format.
protected String format(final String json) throws IOException {
final StringIndenter formatter = new StringIndenter(json);
final Writer outWriter = new StringWriter();
IOUtils.copy(new StringReader(formatter.result()), outWriter, 2048);
outWriter.close();
return outWriter.toString();
}
Aggregations