I'm trying to deserialize the response I receive from a service in XML format and I'm having problems since it tells me that the name is already repeated, but otherwise I don't know how I can do it... I'm sending you the error, the code and the XML which I need to deserialize.
org.simpleframework.xml.core.PersistenceException: Element 'channelLevel' is already used
<channels>
<channelLevel ref="00000000-0000-1000-0000-000000000016">
<id>001</id>
<name>Max</name>
<order>100</order>
<country>MX</country>
</channelLevel >
<channelLevel refId="00000000-0000-1000-0000-000000000017">
<id>001</id>
<name>Max</name>
<order>100</order>
<country>MX</country>
</channelLevel >
<channelLevel refId="00000000-0000-1000-0000-000000000018">
<id>001</id>
<name>Max</name>
<order>100</order>
<country>MX</country>
</channelLevel >
<channelLevel refId="00000000-0000-1000-0000-000000000019">
<id>001</id>
<name>Max</name>
<order>100</order>
<country>MX</country>
</channelLevel >
</channels>
@Root(name = "channels", strict = false)
data class ChannelsList(
@field:ElementList(name = "channelLevel", required = false)
var channelLevel: List<Channels>
)
@Root(name = "channelLevel", strict = false)
data class Channels(
@field:Element(name = "id", required = false)
var id: Int? = null,
@field:Element(name = "name", required = false)
var name: String? = null,
@field:Element(name = "order", required = false)
var order: Int? = null,
@field:Element(name = "country", required = false)
var country: String? = null,
)
Your problem is not related to retrofit but to the serializer you are using. In its documentation it says that if elements don't have a wrapping parent, you should add
inline=true
to the annotation.And you also need to add a default value to the property
channelLevel