I'm trying to get Jackson to produce an XML header like JAXB does, but I can't figure out how to add the "standalone='yes'?"
Example:
public class XmlTest {
@XmlRootElement
public static class Book {
}
@Test
public void testBookXml() throws JsonProcessingException {
XmlMapper mapper = new XmlMapper();
mapper.configure(ToXmlGenerator.Feature.WRITE_XML_DECLARATION, true);
System.out.println("Jackson\n" + mapper.writeValueAsString(new Book()) + "\n");
StringWriter sw = new StringWriter();
JAXB.marshal(new Book(), sw);
System.out.println("JAXB\n" + sw.toString());
}
}
The output is this:
Jackson
<?xml version='1.0' encoding='UTF-8'?><Book/>
JAXB
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<book/>
I don't care about <Book/> vs <book/>. Other than String manipulation, is there a way to get the Jackson header to be like the JAXB one?