I'm trying to consume XML using SimpleXML by Retrofit 2. After hours of struggling with Kotlin I decided to try Java version and the convert then to Kotlin. And Java version worked well...
error:
java.lang.RuntimeException: org.simpleframework.xml.core.MethodException: Annotation @org.simpleframework.xml.ElementList(data=false, empty=true, entry=, inline=true, name=entry, required=true, type=void) must mark a set or get method
I need a Kotlin model class that will be able to consume that XML. Here's input:
<feed>
<entry>
<id> someid </id>
<published> somedate </published>
</entry>
<entry>
<id> someid2 </id>
<published> somedate2 </published>
</entry>
</feed>
Java model class version (works fine):
@Root(name = "feed", strict = false)
public class MFeed {
@ElementList(name = "entry", inline = true)
private List<MEntry> entriesList;
public MFeed(List<MEntry> entriesList) {
this.entriesList = entriesList;
}
public MFeed() {
}
public List<MEntry> getEntriesList() {
return entriesList;
}
public void setEntriesList(List<MEntry> entriesList) {
this.entriesList = entriesList;
}
}
@Root(name = "entry", strict = false)
public class MEntry {
@Element(name = "id")
private String id;
@Element(name = "published")
private String published;
public MEntry() {
}
public MEntry(String id, String published) {
this.id = id;
this.published = published;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getPublished() {
return published;
}
public void setPublished(String published) {
this.published = published;
}
}
and autogenerated Kotlin models look like this:
@Root(name = "feed", strict = false)
class Feed {
@ElementList(name = "entry", inline = true)
private var entriesList: List<MEntry>? = null
//autogenerated by converter java -> kotlin
constructor(entriesList: List<MEntry>) {
this.entriesList = entriesList
}
//autogenerated by converter java -> kotlin
constructor() {}
}
@Root(name = "entry", strict = false)
class Entry {
@Element(name = "id")
var id: String? = null
@Element(name = "published")
var published: String? = null
//autogenerated by converter java -> kotlin
constructor() {}
//autogenerated by converter java -> kotlin
constructor(id: String, published: String) {
this.id = id
this.published = published
}
}
I've serfed a lot for consuming XML lists including this post, this and this. None worked. Perhaps they are obsolete. Anyone faced such problem?