tikxml
tikxml copied to clipboard
Support for reading List<String> and other primitves
As reported in #44 parsing an xml like
<week>
<day>Monday</day>
<day>Tuesday</day>
<day>Wednesday</day>
<day>Thursday</day>
<day>Friday</day>
<day>Saturday</day>
<day>Sunday</day>
</week>
is not possible with @PropertyElement
nor with @Element List<String>
directly.
The current workaround is to use @TextContent
but this requires an extra wrapper:
@Xml
public class Week {
@Element
List<Day> days;
}
@Xml
public class Day {
@TextContent String name;
}
On Latest also i.e 0.8.13, Can't we use @Element List<String> directly? it is giving exception like com.tickaroo.tikxml.TypeAdapterNotFoundException: No TypeAdapter for class java.lang.String found. Expected name of the type adapter is java.lang.String$$TypeAdapter
You can use @Element
on a List like List<SomeClass>
but not on a list of primitives like List<String>
, List<Int>
and List<Double>`.
For List<String>
a workaround is needed right now:
@Xml
public class SomeData {
@Element
List<String> someStrings;
}
@Xml
public class StringWorkaround {
@TextContent String stringValue;
}
then you can parse it as a List<StringWorkaround>
@sockeqwe But in my case not working. items always null
@Xml(name = "data")
public class Data{
...
@Path("Items")
@Element
private List<Item> items;
....
@Xml(name = "item")
public static class Item {
@PropertyElement(name = "type")
private int type;
....
}
XML content
<?xml version="1.0" encoding="utf-8"?>
<data>
…xml
<Items>
<item>
…
<type>1</type>
</item>
</Items>
…
</workspace>