Example usage for org.springframework.oxm.xstream XStreamMarshaller setStreamDriver

List of usage examples for org.springframework.oxm.xstream XStreamMarshaller setStreamDriver

Introduction

In this page you can find the example usage for org.springframework.oxm.xstream XStreamMarshaller setStreamDriver.

Prototype

public void setStreamDriver(HierarchicalStreamDriver streamDriver) 

Source Link

Document

Set a XStream HierarchicalStreamDriver to be used for readers and writers.

Usage

From source file:com.acc.xstream.JsonXStreamMarshallerFactory.java

/**
 * creates a custom json writer which swallows top most root nodes
 *///from   w w w .jav  a2s  .  co m
@Override
protected XStreamMarshaller createMarshaller() {
    final XStreamMarshaller marshaller = super.createMarshaller();
    marshaller.setStreamDriver(new com.thoughtworks.xstream.io.json.JsonHierarchicalStreamDriver() {
        @Override
        public HierarchicalStreamWriter createWriter(final Writer writer) {
            return new JsonWriter(writer, JsonWriter.DROP_ROOT_MODE);
        }
    });
    return marshaller;
}

From source file:com.acc.xstream.XmlXStreamMarshallerFactory.java

protected XStreamMarshaller createMarshaller() {
    //final XStream localXStream = getXStream();

    final StaxDriver driver = new StaxDriver() {
        @Override/*from  ww w .  j  a  v  a 2s  .  co  m*/
        public StaxWriter createStaxWriter(final XMLStreamWriter out) throws XMLStreamException {
            out.writeStartDocument("UTF-8", "1.0");
            return createStaxWriter(out, false);
        }
    };

    final XStreamMarshaller marshaller = new XStreamMarshaller() {
        @Override
        public XStream getXStream() {
            return XmlXStreamMarshallerFactory.this.getXStream();
        }
    };
    marshaller.setStreamDriver(driver);

    return marshaller;
}