Search in sources :

Example 1 with JettisonMappedXmlDriver

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

the class XStreamMarshallerTests method jettisonDriver.

@Test
public void jettisonDriver() throws Exception {
    marshaller.setStreamDriver(new JettisonMappedXmlDriver());
    Writer writer = new StringWriter();
    marshaller.marshal(flight, new StreamResult(writer));
    assertEquals("Invalid result", "{\"flight\":{\"flightNumber\":42}}", writer.toString());
    Object o = marshaller.unmarshal(new StreamSource(new StringReader(writer.toString())));
    assertTrue("Unmarshalled object is not Flights", o instanceof Flight);
    Flight unflight = (Flight) o;
    assertNotNull("Flight is null", unflight);
    assertEquals("Number is invalid", 42L, unflight.getFlightNumber());
}
Also used : StringWriter(java.io.StringWriter) StreamResult(javax.xml.transform.stream.StreamResult) StreamSource(javax.xml.transform.stream.StreamSource) StringReader(java.io.StringReader) JettisonMappedXmlDriver(com.thoughtworks.xstream.io.json.JettisonMappedXmlDriver) 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)

Example 2 with JettisonMappedXmlDriver

use of com.thoughtworks.xstream.io.json.JettisonMappedXmlDriver in project drools by kiegroup.

the class XStreamJSon method newJSonMarshaller.

public static XStream newJSonMarshaller() {
    JettisonMappedXmlDriver jet = new JettisonMappedXmlDriver();
    XStream xstream = createTrustingXStream(jet);
    XStreamHelper.setAliases(xstream);
    xstream.alias("commands", CommandsObjectContainer.class);
    xstream.alias("objects", ObjectsObjectContainer.class);
    xstream.alias("item", RowItemContainer.class);
    xstream.alias("parameters", ParameterContainer.class);
    xstream.alias("results", WorkItemResultsContainer.class);
    xstream.setMode(XStream.NO_REFERENCES);
    xstream.registerConverter(new JSonFactHandleConverter(xstream));
    xstream.registerConverter(new JSonBatchExecutionResultConverter(xstream));
    xstream.registerConverter(new JSonInsertConverter(xstream));
    xstream.registerConverter(new JSonFireAllRulesConverter(xstream));
    xstream.registerConverter(new JSonBatchExecutionCommandConverter(xstream));
    xstream.registerConverter(new CommandsContainerConverter(xstream));
    xstream.registerConverter(new JSonGetObjectConverter(xstream));
    xstream.registerConverter(new JSonRetractConverter(xstream));
    xstream.registerConverter(new JSonModifyConverter(xstream));
    xstream.registerConverter(new JSonSetGlobalConverter(xstream));
    xstream.registerConverter(new JSonInsertElementsConverter(xstream));
    xstream.registerConverter(new JSonGetGlobalConverter(xstream));
    xstream.registerConverter(new JSonGetObjectsConverter(xstream));
    xstream.registerConverter(new JSonQueryConverter(xstream));
    xstream.registerConverter(new JSonQueryResultsConverter(xstream));
    xstream.registerConverter(new RowItemConverter(xstream));
    xstream.registerConverter(new JSonStartProcessConvert(xstream));
    xstream.registerConverter(new JSonSignalEventConverter(xstream));
    xstream.registerConverter(new JSonCompleteWorkItemConverter(xstream));
    xstream.registerConverter(new JSonAbortWorkItemConverter(xstream));
    xstream.registerConverter(new JSonGetSessionTimeConverter(xstream));
    xstream.registerConverter(new JSonAdvanceSessionTimeConverter(xstream));
    return xstream;
}
Also used : XStream(com.thoughtworks.xstream.XStream) XStreamUtils.createTrustingXStream(org.kie.soup.commons.xstream.XStreamUtils.createTrustingXStream) JettisonMappedXmlDriver(com.thoughtworks.xstream.io.json.JettisonMappedXmlDriver)

Aggregations

JettisonMappedXmlDriver (com.thoughtworks.xstream.io.json.JettisonMappedXmlDriver)2 XStream (com.thoughtworks.xstream.XStream)1 HierarchicalStreamWriter (com.thoughtworks.xstream.io.HierarchicalStreamWriter)1 JsonWriter (com.thoughtworks.xstream.io.json.JsonWriter)1 StringReader (java.io.StringReader)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 StreamSource (javax.xml.transform.stream.StreamSource)1 Test (org.junit.Test)1 XStreamUtils.createTrustingXStream (org.kie.soup.commons.xstream.XStreamUtils.createTrustingXStream)1