parent
247d2bb0ae
commit
38062c3373
|
@ -57,6 +57,7 @@ import com.thoughtworks.xstream.io.xml.DomReader;
|
||||||
import com.thoughtworks.xstream.io.xml.DomWriter;
|
import com.thoughtworks.xstream.io.xml.DomWriter;
|
||||||
import com.thoughtworks.xstream.io.xml.QNameMap;
|
import com.thoughtworks.xstream.io.xml.QNameMap;
|
||||||
import com.thoughtworks.xstream.io.xml.SaxWriter;
|
import com.thoughtworks.xstream.io.xml.SaxWriter;
|
||||||
|
import com.thoughtworks.xstream.io.xml.StaxDriver;
|
||||||
import com.thoughtworks.xstream.io.xml.StaxReader;
|
import com.thoughtworks.xstream.io.xml.StaxReader;
|
||||||
import com.thoughtworks.xstream.io.xml.StaxWriter;
|
import com.thoughtworks.xstream.io.xml.StaxWriter;
|
||||||
import com.thoughtworks.xstream.io.xml.XmlFriendlyNameCoder;
|
import com.thoughtworks.xstream.io.xml.XmlFriendlyNameCoder;
|
||||||
|
@ -694,13 +695,14 @@ public class XStreamMarshaller extends AbstractMarshaller implements BeanClassLo
|
||||||
@Override
|
@Override
|
||||||
protected void marshalXmlStreamWriter(Object graph, XMLStreamWriter streamWriter) throws XmlMappingException {
|
protected void marshalXmlStreamWriter(Object graph, XMLStreamWriter streamWriter) throws XmlMappingException {
|
||||||
try {
|
try {
|
||||||
final StaxWriter writer;
|
StaxWriter writer;
|
||||||
if( streamDriver instanceof StaxDriver){
|
if (this.streamDriver instanceof StaxDriver) {
|
||||||
writer = ((StaxDriver)streamDriver).createStaxWriter(streamWriter);
|
writer = ((StaxDriver) this.streamDriver).createStaxWriter(streamWriter);
|
||||||
}else{
|
|
||||||
writer = new StaxWriter( new QNameMap(),streamWriter, this.nameCoder);
|
|
||||||
}
|
}
|
||||||
doMarshal(graph,writer, null);
|
else {
|
||||||
|
writer = new StaxWriter(new QNameMap(), streamWriter, this.nameCoder);
|
||||||
|
}
|
||||||
|
doMarshal(graph, writer, null);
|
||||||
}
|
}
|
||||||
catch (XMLStreamException ex) {
|
catch (XMLStreamException ex) {
|
||||||
throw convertXStreamException(ex, true);
|
throw convertXStreamException(ex, true);
|
||||||
|
|
|
@ -43,6 +43,8 @@ import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
|
||||||
import com.thoughtworks.xstream.io.json.JettisonMappedXmlDriver;
|
import com.thoughtworks.xstream.io.json.JettisonMappedXmlDriver;
|
||||||
import com.thoughtworks.xstream.io.json.JsonHierarchicalStreamDriver;
|
import com.thoughtworks.xstream.io.json.JsonHierarchicalStreamDriver;
|
||||||
import com.thoughtworks.xstream.io.json.JsonWriter;
|
import com.thoughtworks.xstream.io.json.JsonWriter;
|
||||||
|
import com.thoughtworks.xstream.io.xml.QNameMap;
|
||||||
|
import com.thoughtworks.xstream.io.xml.StaxDriver;
|
||||||
import com.thoughtworks.xstream.security.AnyTypePermission;
|
import com.thoughtworks.xstream.security.AnyTypePermission;
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
@ -176,6 +178,23 @@ class XStreamMarshallerTests {
|
||||||
assertThat(XmlContent.from(writer)).isSimilarTo(EXPECTED_STRING);
|
assertThat(XmlContent.from(writer)).isSimilarTo(EXPECTED_STRING);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void marshalStaxResultXMLStreamWriterDefaultNamespace() throws Exception {
|
||||||
|
QNameMap map = new QNameMap();
|
||||||
|
map.setDefaultNamespace("https://example.com");
|
||||||
|
map.setDefaultPrefix("spr");
|
||||||
|
StaxDriver driver = new StaxDriver(map);
|
||||||
|
marshaller.setStreamDriver(driver);
|
||||||
|
|
||||||
|
XMLOutputFactory outputFactory = XMLOutputFactory.newInstance();
|
||||||
|
StringWriter writer = new StringWriter();
|
||||||
|
XMLStreamWriter streamWriter = outputFactory.createXMLStreamWriter(writer);
|
||||||
|
Result result = StaxUtils.createStaxResult(streamWriter);
|
||||||
|
marshaller.marshal(flight, result);
|
||||||
|
assertThat(XmlContent.from(writer)).isSimilarTo(
|
||||||
|
"<spr:flight xmlns:spr=\"https://example.com\"><spr:flightNumber>42</spr:flightNumber></spr:flight>");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void marshalStaxResultXMLEventWriter() throws Exception {
|
void marshalStaxResultXMLEventWriter() throws Exception {
|
||||||
XMLOutputFactory outputFactory = XMLOutputFactory.newInstance();
|
XMLOutputFactory outputFactory = XMLOutputFactory.newInstance();
|
||||||
|
|
Loading…
Reference in New Issue