[Simple-support] Empty Array Serialization
Brought to you by:
niallg
|
From: Robin D. <rob...@gm...> - 2012-07-31 16:07:20
|
@Root(name = "ArrayTest")
public class ArrayTest {
@Attribute
private long[] coordinates = new long[0];
public static void main(String[] args) throws Exception {
StringWriter writer = new StringWriter();
new Persister().write(new ArrayTest(), writer);
String xml = writer.toString();
new Persister().read(ArrayTest.class, new StringReader(xml));
}
}
*The above fails attempting to parse a long from an empty string - yet the
array is empty!*
Hi - I noticed an issue with deserializing empty primitive (or even
non-primitive) arrays. As empty string is used to represent an empty array,
the split method in the ArrayTransform fails to obtain the correct length
of the list. Split on an empty string results in an array of length 1,
however the original array was empty. I can see there is still an issue
with empty string arrays, however for types which can not possibly have
elements as empty strings such as int arrays. I would suggest the API
refuse to serialize empty arrays if the result will be ambiguous.
If this is a feature not a bug, let me know - I believe I have the latest
source (2.6.6).
Many thanks, love the API by the way - use it loads!
Regards,
Robin
|