[ad_1]
I am currently trying to fetch data from a rss api in android studio using kotlin and retrofit2 and the SimpleXmlConverterFactory.
But I am getting the following exception:
2022-05-30 22:46:36.630 15966-15966/com.example.xmlfit D/Retrofit: We got a cause org.simpleframework.xml.core.PersistenceException: Element 'title' is already used with @org.simpleframework.xml.Element(data=false, name=title, required=false, type=void) on field 'title' private java.lang.String com.example.xmlfit.models.xml.EventList.title at line -1
The problem is when I want to save the items and it hits “title” or “description” a second time.
I have the following classes:
Channel.kt
import org.simpleframework.xml.Element
import org.simpleframework.xml.ElementList
import org.simpleframework.xml.Root
@Root(name = "channel", strict = false)
data class Channel @JvmOverloads constructor(
@field:Element(name = "title", required = false)
@param:Element(name = "title", required = false)
var title: String? = null,
@param:Element(name = "description", required = false)
@field:Element(name = "description", required = false)
private var description: String? = null,
@field:ElementList(entry="item", inline = true)
@param:ElementList(entry="item", inline = true)
var eventList: List<EventList>? =
null
)
RssFeed.kt
package com.example.xmlfit.models.xml
import org.simpleframework.xml.Element
import org.simpleframework.xml.Root
@Root(name = "rss", strict = false)
data class RssFeed @JvmOverloads constructor(
@param:Element(name = "channel", required = false)
@field:Element(
required = false,
name = "channel")
var channel: Channel? = null,
)
EventList.kt
package com.example.xmlfit.models.xml
import org.simpleframework.xml.Element
import org.simpleframework.xml.Root
@Root(name = "item", strict = false)
data class EventList @JvmOverloads constructor(
@field:Element(name = "title", required = false)
@param:Element(name = "title", required = false)
private var title: String? = null,
@field:Element(name = "link", required = false)
@param:Element(name = "link", required = false)
var link: String? = null,
@field:Element(name = "description", required = false)
@param:Element(name = "description", required = false)
private var description: String? = null,
)
Xml Structure:
<rss version="2.0">
<channel>
<title>Events today</title>
<link>
</link>
<description> Events in your town </description>
<lastBuildDate>Mo,30 Mai 2022 22:38:30 GMT</lastBuildDate>
<language>de-AT</language>
<item>
<title>Strand Event 2022</title>
<description>
<p>01.04.2022 bis 30.09.2022 This Event takes place on a sand.</p>
</description>
<category/>
</item>
<item>
<title>Summerstage 2022</title>
<description>
<p>28.06.2022 bis 30.06.2022 Summer is here.</p>
</description>
<category/>
</item>
</channel>
</rss>
I have already tried the following approache without success:
changing annotations to for the item element title and description:
@Path("title")
@Text(required = false)
leads to the following exception:
2022-05-30 22:57:33.796 16046-16046/com.example.xmlfit D/Retrofit: We got a cause org.simpleframework.xml.core.ConstructorException: Parameter 'title[1]' does not have a match in class com.example.xmlfit.models.xml.EventList
And if important the following implementation in the gradle file (in the meantime there are also redundant things i think):
implementation "com.squareup.retrofit2:retrofit:$retrofit_version"
implementation "com.squareup.retrofit2:converter-simplexml:$retrofit_version"
implementation 'com.squareup.retrofit2:adapter-rxjava2:2.9.0'
implementation "com.squareup.retrofit2:converter-gson:$retrofit_version"
Thanks in advance!
[ad_2]