My first suggestion is to never serialize root-level Collections, Lists or Maps.
Even on a good day, Type Erasure is likely to cause issues; and instead to use a POJO. Collections/Map work just fine on any other level.
Also some of annotations that are available for properties can not be used for types, or are cumbersome to use.
So in this case, the usual way of changing root element name (@XmlRootElement or equivalent) is not available, unless you sub-class ArrayList. While this is doable (i.e. you can create subtype, add annotation), a better alternative may be to define root name override via writer:
String xml = xmlMapper
.writer()
.withRootName("foos")
.writeValueAsString(list);
The other problem, however, is something I don't know answer to.
If this was a property, it would be done using @XmlElementWrapper.
Choice of "item", for root-level Collections, is essentially hard-coded; comment in XmlSerializerProvider saying:
// Could repeat root name, but what's the point? How to customize?
so that the thought of allowing it to be changed has crossed my mind at some point. I am open to suggestions for configuring this. An easy thing would be to add a setter for XML module / mapper to change String.
Finding root name for value is trickier, since type information may or may not be available; peeking at first value might work.
Hope this helps,
-+ Tatu +-