There is no property that you can configure. Most implementations send a line separator directly to the buffer:
write('\n');
However, you can replace the result.
Marshaller marshaller = ctx.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8"); StringWriter writer = new StringWriter(1024); // 2 KB marshaller.marshal(obj, writer); String str = writer.toString(); str = str.replace("\n", "\r\n");
To avoid any performance impact, you should set the approximate size (for example, 1024 -> 2 KB ) in the constructor for java.io.StringWriter .
source share