Deserialize a list of string elements w/ simple-and and retrofit on Android

83 Views Asked by At

I am using the simple-xml library (https://simple.sourceforge.net/home.php) to deserialize a list of string elements.

<Parent>
  <PropertyList>
    <Entry>image/png</Entry>
    <Entry>application/atom+xml</Entry>
    <Entry>application/json;type=utfgrid</Entry>

Which I successfully deserialize with:

data class PropertyList(
   @field:ElementList(name = "Entry", inline = true)
   var entries: List<Entry> = mutableListOf()
)

@Root(name = "Entry", strict = false)
class Entry(
   @field:Text
   var entry: String? = null
)

However I am trying to figure out if I can remove the extra Entry class and just deserialize into a list of Strings:

data class PropertyList(
   @field:ElementList(name = "Entry", inline = true)
   var entries: List<String> = mutableListOf()
)

When I try that I end up with an empty list. Is this possible?

1

There are 1 best solutions below

0
Charfeddine Mohamed Ali On

you can annotate the entries field in your PropertyList class with @field:ElementList(inline = true, entry = "Entry", required = false), like this:

data class PropertyList(
    @field:ElementList(inline = true, entry = "Entry", required = false)
    var entries: List<String> = mutableListOf()
)