Skip to content

Commit

Permalink
When marshalling to XMLStreamWriter, JAXB (both Sun/Oracle and MOXy v…
Browse files Browse the repository at this point in the history
…ariants) omits encoding, so add it here.
  • Loading branch information
plutext committed Aug 1, 2018
1 parent 73d07b4 commit 78e6bab
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
Expand Up @@ -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);
Expand Down
11 changes: 8 additions & 3 deletions src/main/java/org/docx4j/utils/XMLStreamWriterWrapper.java
Expand Up @@ -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);

}
Expand Down

0 comments on commit 78e6bab

Please sign in to comment.