Re: [Simple-support] How can I make Simple not to serialize empty ArrayList?
Brought to you by:
niallg
|
From: Niall G. <gal...@ya...> - 2014-07-31 22:42:18
|
You can use a converter, it should be able to remove the tag. The problem here is how do you distinguish null from an empty list. The tag is needed for this in order to do a verbatim serialization/deserialization.
--------------------------------------------
On Fri, 1/8/14, Vojtěch Rýznar <ry...@ce...> wrote:
Subject: [Simple-support] How can I make Simple not to serialize empty ArrayList?
To: sim...@li...
Received: Friday, 1 August, 2014, 6:26 AM
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
-----Inline Attachment Follows-----
------------------------------------------------------------------------------
Infragistics Professional
Build stunning WinForms apps today!
Reboot your WinForms applications with our WinForms
controls.
Build a bridge from your legacy apps to the future.
http://pubads.g.doubleclick.net/gampad/clk?id=153845071&iu=/4140/ostg.clktrk
-----Inline Attachment Follows-----
_______________________________________________
Simple-support mailing list
Sim...@li...
https://lists.sourceforge.net/lists/listinfo/simple-support
|