public static void main(String[] args) throws Exception {
Set<Person> personHashSet = new HashSet<>();
File file = new File(System.getenv("XML_PERSON_FILE_NAME"));
XMLOutputFactory xmlOutputFactory = XMLOutputFactory.newFactory();
XMLStreamWriter sw = xmlOutputFactory.createXMLStreamWriter(new FileOutputStream(file));
XmlMapper mapper = new XmlMapper();
sw.writeStartDocument();
People people = new People();
people.setPerson(personHashSet);
mapper.writeValue(sw, people);
sw.writeComment("Some insightful commentary here");
sw.writeEndDocument();
}
I expect the class People to be written formatted, but in the target file I only get one very long line:
<?xml version='1.0' encoding='UTF-8'?><people><person><id>3</id><name>Vasiliy</name><coordinates><x>1</x><y>2.0</y></coordinates><xmlCreationDate>1609534800000</xmlCreationDate><height>10.0</height><birthday/><hairColor/><nationality/><location/></person><person><id>1</id><name>Oleg</name><coordinates><x>1</x><y>2.0</y></coordinates><xmlCreationDate>1609534800000</xmlCreationDate><height>10.0</height><birthday/><hairColor/><nationality/><location/></person><person><id>2</id><name>Aleksey</name><coordinates><x>1</x><y>2.0</y></coordinates><xmlCreationDate>1609534800000</xmlCreationDate><height>10.0</height><birthday/><hairColor/><nationality/><location/></person></people><!--Some insightful commentary here-->
Is there any possible ways to fix this?