You can refer to this if JAXB doesn't add padding:
Marshaller marshaller = jaxbContext.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, false);
If you use the JAXB class to save to XML, it automatically formats the document. To remove formatting, do not follow these steps, just use the above approach:
JAXB.marshal(object, System.out);
You can also try a different JAXB implementation. I lead the implementation of MOXy JAXB . When our implementation formats a document, the following is used.
System.getProperty("line.separator");
source share