Search in sources :

Example 1 with JsonWriter

use of com.thoughtworks.xstream.io.json.JsonWriter in project spring-framework by spring-projects.

the class XStreamMarshallerTests method jsonDriver.

@Test
public void jsonDriver() throws Exception {
    marshaller.setStreamDriver(new JsonHierarchicalStreamDriver() {

        @Override
        public HierarchicalStreamWriter createWriter(Writer writer) {
            return new JsonWriter(writer, JsonWriter.DROP_ROOT_MODE, new JsonWriter.Format(new char[0], new char[0], JsonWriter.Format.SPACE_AFTER_LABEL | JsonWriter.Format.COMPACT_EMPTY_ELEMENT));
        }
    });
    Writer writer = new StringWriter();
    marshaller.marshal(flight, new StreamResult(writer));
    assertEquals("Invalid result", "{\"flightNumber\": 42}", writer.toString());
}
Also used : StringWriter(java.io.StringWriter) StreamResult(javax.xml.transform.stream.StreamResult) HierarchicalStreamWriter(com.thoughtworks.xstream.io.HierarchicalStreamWriter) JsonHierarchicalStreamDriver(com.thoughtworks.xstream.io.json.JsonHierarchicalStreamDriver) JsonWriter(com.thoughtworks.xstream.io.json.JsonWriter) HierarchicalStreamWriter(com.thoughtworks.xstream.io.HierarchicalStreamWriter) JsonWriter(com.thoughtworks.xstream.io.json.JsonWriter) XMLEventWriter(javax.xml.stream.XMLEventWriter) XMLStreamWriter(javax.xml.stream.XMLStreamWriter) Writer(java.io.Writer) StringWriter(java.io.StringWriter) Test(org.junit.Test)

Aggregations

HierarchicalStreamWriter (com.thoughtworks.xstream.io.HierarchicalStreamWriter)1 JsonHierarchicalStreamDriver (com.thoughtworks.xstream.io.json.JsonHierarchicalStreamDriver)1 JsonWriter (com.thoughtworks.xstream.io.json.JsonWriter)1 StringWriter (java.io.StringWriter)1 Writer (java.io.Writer)1 XMLEventWriter (javax.xml.stream.XMLEventWriter)1 XMLStreamWriter (javax.xml.stream.XMLStreamWriter)1 StreamResult (javax.xml.transform.stream.StreamResult)1 Test (org.junit.Test)1