diff --git a/org.springframework.oxm/.classpath b/org.springframework.oxm/.classpath index c6f04682f0f..7ad7981795b 100644 --- a/org.springframework.oxm/.classpath +++ b/org.springframework.oxm/.classpath @@ -7,7 +7,7 @@ - + diff --git a/org.springframework.oxm/ivy.xml b/org.springframework.oxm/ivy.xml index f4e05e3edd8..68d2b194bd9 100644 --- a/org.springframework.oxm/ivy.xml +++ b/org.springframework.oxm/ivy.xml @@ -26,7 +26,7 @@ - diff --git a/org.springframework.oxm/oxm.iml b/org.springframework.oxm/oxm.iml index 2b8d45cb4b7..f1939f9d5a5 100644 --- a/org.springframework.oxm/oxm.iml +++ b/org.springframework.oxm/oxm.iml @@ -1,160 +1,162 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/org.springframework.oxm/pom.xml b/org.springframework.oxm/pom.xml index 541c3ad0ae4..40dd1d97c97 100644 --- a/org.springframework.oxm/pom.xml +++ b/org.springframework.oxm/pom.xml @@ -18,7 +18,7 @@ com.thoughtworks.xstream xstream - 1.3 + 1.3.1 true diff --git a/org.springframework.oxm/src/main/java/org/springframework/oxm/xstream/XStreamMarshaller.java b/org.springframework.oxm/src/main/java/org/springframework/oxm/xstream/XStreamMarshaller.java index 2c4eb79d848..1014066d2b6 100644 --- a/org.springframework.oxm/src/main/java/org/springframework/oxm/xstream/XStreamMarshaller.java +++ b/org.springframework.oxm/src/main/java/org/springframework/oxm/xstream/XStreamMarshaller.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2009 the original author or authors. + * Copyright 2002-2010 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -57,17 +57,17 @@ import org.xml.sax.InputSource; import org.xml.sax.XMLReader; import org.xml.sax.ext.LexicalHandler; -import org.springframework.beans.factory.InitializingBean; import org.springframework.beans.factory.BeanClassLoaderAware; +import org.springframework.beans.factory.InitializingBean; import org.springframework.oxm.MarshallingFailureException; import org.springframework.oxm.UncategorizedMappingException; import org.springframework.oxm.UnmarshallingFailureException; import org.springframework.oxm.XmlMappingException; import org.springframework.oxm.support.AbstractMarshaller; import org.springframework.util.Assert; +import org.springframework.util.ClassUtils; import org.springframework.util.ObjectUtils; import org.springframework.util.StringUtils; -import org.springframework.util.ClassUtils; import org.springframework.util.xml.StaxUtils; /** @@ -397,14 +397,21 @@ public class XStreamMarshaller extends AbstractMarshaller implements Initializin */ private void marshal(Object graph, HierarchicalStreamWriter streamWriter) { try { - this.getXStream().marshal(graph, streamWriter); + getXStream().marshal(graph, streamWriter); } catch (Exception ex) { throw convertXStreamException(ex, true); } + finally { + try { + streamWriter.flush(); + } + catch (Exception ex) { + logger.debug("Could not flush HierarchicalStreamWriter", ex); + } + } } - // Unmarshalling @Override diff --git a/org.springframework.oxm/src/test/java/org/springframework/oxm/xstream/XStreamMarshallerTests.java b/org.springframework.oxm/src/test/java/org/springframework/oxm/xstream/XStreamMarshallerTests.java index 7d307cdc422..a2770ce3164 100644 --- a/org.springframework.oxm/src/test/java/org/springframework/oxm/xstream/XStreamMarshallerTests.java +++ b/org.springframework.oxm/src/test/java/org/springframework/oxm/xstream/XStreamMarshallerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2009 the original author or authors. + * Copyright 2002-2010 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -38,7 +38,10 @@ import javax.xml.transform.stream.StreamSource; import com.thoughtworks.xstream.converters.Converter; import com.thoughtworks.xstream.converters.extended.EncodedByteArrayConverter; +import com.thoughtworks.xstream.io.HierarchicalStreamWriter; import com.thoughtworks.xstream.io.json.JettisonMappedXmlDriver; +import com.thoughtworks.xstream.io.json.JsonHierarchicalStreamDriver; +import com.thoughtworks.xstream.io.json.JsonWriter; import static org.custommonkey.xmlunit.XMLAssert.*; import static org.easymock.EasyMock.*; import static org.junit.Assert.assertEquals; @@ -258,7 +261,7 @@ public class XStreamMarshallerTests { } @Test - public void driver() throws Exception { + public void jettisonDriver() throws Exception { marshaller.setStreamDriver(new JettisonMappedXmlDriver()); Writer writer = new StringWriter(); marshaller.marshal(flight, new StreamResult(writer)); @@ -270,6 +273,20 @@ public class XStreamMarshallerTests { assertEquals("Number is invalid", 42L, unflight.getFlightNumber()); } + @Test + public void jsonDriver() throws Exception { + marshaller.setStreamDriver(new JsonHierarchicalStreamDriver() { + @Override + public HierarchicalStreamWriter createWriter(Writer writer) { + return new JsonWriter(writer, new char[0], "", JsonWriter.DROP_ROOT_MODE); + } + }); + + Writer writer = new StringWriter(); + marshaller.marshal(flight, new StreamResult(writer)); + assertEquals("Invalid result", "{\"flightNumber\": 42}", writer.toString()); + } + @Test public void testAnnotatedMarshalStreamResultWriter() throws Exception { marshaller.setAnnotatedClass(Flight.class);