Using Jackson XmlMapper for serialization in XML DOM

I know that you can serialize directly to String using XmlMapper.writeValueAsString() , but I would like to serialize the DOM tree. Any new document, or preferably serialized directly into an existing DOM Node. Can this be done with Jackson?

+6
source share
1 answer

I think I found a solution using XMLStreamWriter .

Try the following snippet:

 XMLOutputFactory factory = XMLOutputFactory.newInstance(); factory.createXMLStreamWriter(new DOMResult(yourNode)); XmlMapper mapper = new XmlMapper(); ToXmlGenerator xmlGenerator = mapper .getFactory().createGenerator(sw); mapper.writerFor(YourClass.class).writeValue(xmlGenerator, yourInstance); 
0
source

Source: https://habr.com/ru/post/947752/


All Articles