I am trying to parse xml data to Kotlin/Java and can't figure out how to do it properly. Simpleframework throws
org.simpleframework.xml.core.PersistenceException: Constructor not matched for class openaire.model.Publication
which doesnt really help.
XML:
<response>
<header>
<size>60</size>
<page>1</page>
<total>116600160</total>
</header>
<publications>
<publication>
<openaireid>od______1318::206c086e81631b3cde0eca4acb2d0ea2</openaireid>
<doi>10.22337/1524-5845-2016-12-3-104-113</doi>
<doi>10.22337/1524-5845-2016-12-3-104-113</doi>
<description>Peer reviewed</description>
<publicationtype>Article</publicationtype>
<title>Neuroleptiques à uridol (R16341)</title>
<authors>
<author>Bobon, Jean</author>
<author>Mélon, Jean</author>
</authors>
<dateofacceptance>1970-01-01</dateofacceptance>
<sourcejournal>Crossref</sourcejournal>
<sourcejournal>Neuroleptiques</sourcejournal>
<webresource>http://ijccse.iasv.ru/</webresource>
<webresource>https://academic.microsoft.com</webresource>
<bestlicense>OPEN</bestlicense>
</publication>
.....
</publications>
</response>
Kotlin Class: I think the error might be in the Element lists doi, source journal or web resource.
@Root(name = "response", strict = false)
class OpenaireModel @JvmOverloads constructor(
var header: Header,
@field:Element(name = "publications")
var publications: Publications,
)
@Root(name = "header", strict = false)
class Header @JvmOverloads constructor(
@field:Element(name = "size")
var size: Int,
@field:Element(name = "page")
var page: Int,
@field:Element(name = "total")
var total: Int
)
@Root(name = "authors", strict = false)
class Authors @JvmOverloads constructor(
@field:ElementList(inline = true, required = false)
var author: List<String> = mutableListOf()
)
@Root(name = "publication", strict = false)
class Publication @JvmOverloads constructor(
@field:Element(name = "openaireid")
var openaireid: String? = null,
@field:ElementList(
required = false,
name = "doi",
entry = "doi",
inline = true,
empty = true
)
var dois: List<Doi>? = null,
@field:Element(name = "description", required = false)
var description: String? = null,
@field:Element(name = "publicationtype")
var publicationtype: String? = null,
@field:Element(name = "title")
var title: String? = null,
@field:Element(name = "authors")
var authors: Authors,
@field:ElementList(
required = false,
name = "sourcejournal",
entry = "sourcejournal",
inline = true,
empty = true
)
var sources: List<Sourcejournal>? = null,
@field:Element(name = "dateofacceptance")
var dateofacceptance: String? = null,
@field:ElementList(
required = false,
name = "webresource",
entry = "webresource",
inline = true,
empty = true
)
var resources: List<Webresource>? = null,
@field:Element(name = "bestlicense")
var bestlicense: String? = null
)
@Root(name = "webresource", strict = false)
class Webresource @JvmOverloads constructor(
@field:Text
var text: String? = null
)
@Root(name = "sourcejournal", strict = false)
class Sourcejournal @JvmOverloads constructor(
@field:Text
var text: String? = null
)
@Root(name = "doi", strict = false)
class Doi @JvmOverloads constructor(
@field:Text
var text: String? = null
)
@Root(name = "publications", strict = false)
class Publications @JvmOverloads constructor(
@field:ElementList(inline = true)
var publication: List<Publication>
)