I'm using FasterXML to serialize POJO. I want to serialize a list of my POJO. When serialize a signle POJO I get the expected xml (there's one problem --> question 2) Here's my code:
List<Movie> movies = new ArrayList<>();
// add movies
JacksonXmlModule module = new JacksonXmlModule();
module.setDefaultUseWrapper(false);
xmlMapper = new XmlMapper(module);
xmlMapper.disable(MapperFeature.AUTO_DETECT_CREATORS,
MapperFeature.AUTO_DETECT_FIELDS,
MapperFeature.AUTO_DETECT_GETTERS,
MapperFeature.AUTO_DETECT_IS_GETTERS,
MapperFeature.AUTO_DETECT_SETTERS,
MapperFeature.USE_GETTERS_AS_SETTERS);
String xml = xmlMapper.writeValueAsString(movies);
I get this:
<ArrayList>
<item imdbID="tt0077687" title="The Hobbit" year="1977"/>
</ArrayList>
Here's what I want:
<movies>
<movie imdbID="tt0077687" title="The Hobbit" year="1977"/>
<movie imdbID="tt0077687" title="title2" year="1977"/>
</movies>
or
<movie imdbID="tt0077687" title="The Hobbit" year="1977"/>
<movie imdbID="tt0077687" title="title2" year="1977"/>
When I serialize a movie I get this:
Is it possible to get this:
<movie imdbID="tt0077687" title="The Hobbit" year="1977"><movie>