https://kotlinlang.org logo
#server
Title
# server
s

Slackbot

08/24/2022, 10:43 PM
This message was deleted.
d

David Nedrow

08/24/2022, 11:15 PM
I would think it would be closer to the following…
Copy code
data class News (
    val error: String, // Boolean?
    val category: String,
    val type: String, // Should this be an enum
    val setup: String,
    val delivery: String,
    val flags: Flags,
    val id: String, // UInt?
    val safe: String, // Boolean?
    val lang: String
)

data class Flags (
    // These could be Boolean
    val nsfw: String,
    val religious: String,
    val political: String,
    val racist: String,
    val sexist: String,
    val explicit: String
)
…making the fields optional where needed.
👍 1
d

DavdF

08/24/2022, 11:43 PM
Thanks David I will try it out now!
I am getting this error:
Copy code
Caused by: nl.adaptivity.xmlutil.serialization.UnknownXmlFieldException: Could not find a field for name News/error
  candidates: error, category, type, setup, delivery, Flags, id, safe, lang at position [row,col {unknown-source}]: [3,5]
I dont understand becasue I do have error
d

David Nedrow

08/25/2022, 4:18 PM
Try setting error to
Boolean
rather than
String
.
Oh, and you marked the data classes as
@Serializable
?
d

DavdF

08/26/2022, 11:39 PM
@David Nedrow Yes in ktor I was trying to use
Copy code
import io.ktor.serialization.kotlinx.xml.*
for the XML certification. I have switch to just parcing the the XML first and then turning it into JSON to send back out to the client.
Copy code
io.ktor.serialization.kotlinx.xml.*
Needs a lot better documentation!
👍🏻 1
d

David Nedrow

08/29/2022, 1:09 PM
Especially up to date documentation.
h

hhariri

08/30/2022, 1:35 PM
@DavdF I appreciate that you are looking for support, and maybe this is an example not of your doing, but please be considerate when posting contents. The contents of your XML is not appropriate. Please remove it/replace it. Thank you
👍🏻 1
m

marlonlom

09/05/2022, 2:27 PM
I did convert the xml to data classes using this webpage:
https://jsonformatter.org/xml-to-kotlin
Copy code
data class Data (
    val error: String,
    val category: String,
    val type: String,
    val setup: String,
    val delivery: String,
    val flags: Flags,
    val id: String,
    val safe: String,
    val lang: String
)

data class Flags (
    val nsfw: String,
    val religious: String,
    val political: String,
    val racist: String,
    val sexist: String,
    val explicit: String
)
🙌 1
11 Views