Jackson XML globally set element name for container types
- by maxenglander
I'm using Jackson 1.9.2 with the XML databind module. I need to tweak the way that Jackson serializes arrays, lists, collections.
By default, with an int array property called myProperty containing a couple numbers, Jackson / XML is producing the following:
<myProperty>
<myProperty>1</myProperty>
<myProperty>2</myProperty>
</myProperty>
What I need to produce is:
<myProperty>
<item>1</item>
<item>2</item>
</myProperty>
I can do this on a per-POJO basis using a combination of JacksonXmlElementWrapper and JacksonXmlProperty like so:
@JacksonXmlElementWrapper(localname='myProperty')
@JacksonXmlProperty(localname='item')
public int[] myProperty;
This solution, however, would require that I manually apply these annotations to every array, list, collection in my POJOs. A much better solution would allow me to apply a solution once, globally, for all array, list, collection types. Any ideas on how to implement such a solution?
Thanks!