Allow writing Comments in Document Prolog (before root element) (original) (raw)
Now that we have a mechanism -- XmlGeneratorInitializer -- for passing information on things to write before regular XML Document, let's add a way to add XML Comments in "prolog" (that is, after XML Declarations, if any; but before the root element).
Planned usage:
ObjectWriter w = XmlMapper.builder().writer()
.with(new XmlGeneratorInitializer().addComment(" Comment content! ")
// possible other directives or XML Decl customization
);
String xml = w.writeValueAsString(new MyValue);
// we get:
//
// <!-- Comment content! -->
// <value>...</value>