Escape policy for quote (") is different when the serialization is performed to OutputStream or Writer · Issue #868 · javaee/jaxb-v2 (original) (raw)

When comparing com.sun.xml.bind.marshaller.MinimumEscapeHandler and com.sun.xml.bind.v2.runtime.output.Encoded one can see that quote (") symbol is processed differently. When the bean is serialized to Writer, quotes for text nodes are printed as (") symbol, while when the same bean is serialized to OutputStream, it is printed as ("). The difference is caused by Encoded.java:201:

add('"',""",false);
which should be changed to
add('"',""",true);

Pseudo test case:

bean.setText("Some \"quoted \" text");

StringWriter writer = new StringWriter();
ByteArrayOutputStream stream = new ByteArrayOutputStream();

JAXBUtils.serializeBean(bean, new StreamResult(writer));
JAXBUtils.serializeBean(bean, new StreamResult(stream));

assertEquals(value, writer.toString());
assertEquals(value, stream.toString());

Also I've noticed that order of namespaces and attributes is different: for writer it is [attributes, namespaces] and for stream it is [namespaces, attributes]. Can't fire a bug though but handy if that is changed as well...

Affected Versions

[2.2.4u1]