[Simple-support] How can I make Simple not to serialize empty ArrayList?
Brought to you by:
niallg
|
From: Vojtěch R. <ry...@ce...> - 2014-07-31 20:45:09
|
Good day, I need an advice please. let's say I have class Person:
|@Root(name="Person")
public class Person {
@Element(name="Name")
public String name= "MyName"
@ElementList(name="AddressList", entry="Address", required=false)
public ArrayList<Address> addressList= new ArrayList<>();
}|
... and class Address:
|public class Address {
@Element(name="Street")
public String street;
@Element(name="City")
public String city;
}|
When addressList has no items Simple produces this XML:
|<Person>
<Name>MyName</Name>
<AddressList/>
</Person>|
Please, how can I make Simple omit tag *AddressList* if there are no
items on the list? I want the XML look like this in such case:
|<Person>
<Name>MyName</Name>
</Person>|
I don't want to set the addressList to null. When I create Person object
I want the addressList to be initialized so that I can easily add
addresses if needed and I don't need to check whehter it is null and
instantiate it. The example above is very simple but when my object
hierarchy is more complicated it is unconvenient to check and initialize
all lists. I hoped I could resolve it using some anotation or custom
converter or something like that.
Thank you in advance. Vojta
|