Permalink
Browse files

When marshalling to XMLStreamWriter, JAXB (both Sun/Oracle and MOXy v…

…ariants) omits encoding, so add it here.
  • Loading branch information...
plutext committed Aug 1, 2018
1 parent 73d07b4 commit 78e6babe0e964c8f83051a4c7fd68db45ef6e9ba
@@ -828,7 +828,7 @@ public void marshal(java.io.OutputStream os, Object namespacePrefixMapper) throw
} else {
XMLOutputFactory xof = XMLOutputFactory.newFactory();
XMLStreamWriter xsw = xof.createXMLStreamWriter(os);
XMLStreamWriter xsw = xof.createXMLStreamWriter(os, "UTF-8");
// get rid of xmlns="" which com.sun.xml.internal.stream.writers.XMLStreamWriterImpl writes
XMLStreamWriterWrapper xsww = new XMLStreamWriterWrapper(this, xsw);
@@ -176,21 +176,26 @@ public void writeEntityRef(String name) throws XMLStreamException {
underlying.writeEntityRef(name);
}
@Override
public void writeStartDocument() throws XMLStreamException {
underlying.writeStartDocument();
// Sun/Oracle JAXB always invokes this
log.debug("writeStartDocument ");
writeStartDocument("UTF-8", "1.0");
}
@Override
public void writeStartDocument(String version) throws XMLStreamException {
underlying.writeStartDocument(version);
// MOXy always invokes this
log.debug("writeStartDocument " + version);
writeStartDocument("UTF-8", version);
}
@Override
public void writeStartDocument(String encoding, String version) throws XMLStreamException {
log.debug("writeStartDocument " + encoding);
underlying.writeStartDocument(encoding, version);
}

0 comments on commit 78e6bab

Please sign in to comment.