Search in sources :

Example 1 with StringIndenter

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();
    }
}
Also used : XMLStreamWriter(javax.xml.stream.XMLStreamWriter) OutputStream(java.io.OutputStream) CachedOutputStream(org.apache.cxf.io.CachedOutputStream) StringIndenter(org.codehaus.jettison.util.StringIndenter) StringReader(java.io.StringReader) OutputStreamWriter(java.io.OutputStreamWriter) MessageContext(org.apache.cxf.jaxrs.ext.MessageContext) XMLStreamWriter(javax.xml.stream.XMLStreamWriter) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter) W3CDOMStreamWriter(org.apache.cxf.staxutils.W3CDOMStreamWriter) CachedOutputStream(org.apache.cxf.io.CachedOutputStream)

Example 2 with StringIndenter

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();
}
Also used : StringWriter(java.io.StringWriter) StringIndenter(org.codehaus.jettison.util.StringIndenter) StringReader(java.io.StringReader) StringWriter(java.io.StringWriter) Writer(java.io.Writer)

Aggregations

StringReader (java.io.StringReader)2 Writer (java.io.Writer)2 StringIndenter (org.codehaus.jettison.util.StringIndenter)2 OutputStream (java.io.OutputStream)1 OutputStreamWriter (java.io.OutputStreamWriter)1 StringWriter (java.io.StringWriter)1 XMLStreamWriter (javax.xml.stream.XMLStreamWriter)1 CachedOutputStream (org.apache.cxf.io.CachedOutputStream)1 MessageContext (org.apache.cxf.jaxrs.ext.MessageContext)1 W3CDOMStreamWriter (org.apache.cxf.staxutils.W3CDOMStreamWriter)1