Search in sources :

Example 1 with XStreamMarshaller

use of org.springframework.oxm.xstream.XStreamMarshaller in project cia by Hack23.

the class UnmarshallXmlTest method unmarshallTest.

/**
 * Unmarshall test.
 *
 * @throws Exception
 *             the exception
 */
@Test
public void unmarshallTest() throws Exception {
    final String content = "abcdefg";
    final String xmlContent = "<string>" + content + "</string>";
    File temp;
    temp = File.createTempFile("UnmarshallXmlTestTempFile", ".xml");
    final OutputStreamWriter bw = new OutputStreamWriter(new FileOutputStream(temp), StandardCharsets.UTF_8);
    bw.write(xmlContent);
    bw.close();
    final XStream xstream = new XStream();
    xstream.alias("TestXml", TestXml.class);
    assertEquals(content, unmarshallXml(new XStreamMarshaller(), temp.getAbsolutePath()));
}
Also used : XStream(com.thoughtworks.xstream.XStream) FileOutputStream(java.io.FileOutputStream) OutputStreamWriter(java.io.OutputStreamWriter) XStreamMarshaller(org.springframework.oxm.xstream.XStreamMarshaller) File(java.io.File) Test(org.junit.Test)

Example 2 with XStreamMarshaller

use of org.springframework.oxm.xstream.XStreamMarshaller in project tutorials by eugenp.

the class WebConfig method createXmlHttpMessageConverter.

private HttpMessageConverter<Object> createXmlHttpMessageConverter() {
    final MarshallingHttpMessageConverter xmlConverter = new MarshallingHttpMessageConverter();
    final XStreamMarshaller xstreamMarshaller = new XStreamMarshaller();
    xmlConverter.setMarshaller(xstreamMarshaller);
    xmlConverter.setUnmarshaller(xstreamMarshaller);
    return xmlConverter;
}
Also used : MarshallingHttpMessageConverter(org.springframework.http.converter.xml.MarshallingHttpMessageConverter) XStreamMarshaller(org.springframework.oxm.xstream.XStreamMarshaller)

Aggregations

XStreamMarshaller (org.springframework.oxm.xstream.XStreamMarshaller)2 XStream (com.thoughtworks.xstream.XStream)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 OutputStreamWriter (java.io.OutputStreamWriter)1 Test (org.junit.Test)1 MarshallingHttpMessageConverter (org.springframework.http.converter.xml.MarshallingHttpMessageConverter)1