when using a private constructor then a public constructor, it displays the public one as unused. Shouldn't kotlinx serialization somehow indicate that it will be used for serialization?
e
ephemient
11/05/2022, 4:23 AM
kotlinx.serialization uses the primary constructor. if you mean something like
in that example, "Serialization works with a private primary constructor"
ephemient
11/05/2022, 4:28 AM
what is the other way around about it?
z
zt
11/05/2022, 4:29 AM
Copy code
@Serializable
internal class ApiText private constructor(private val text: String) {
constructor(runs: List<TextRun>) : this(
text = runs.joinToString(separator = "", transform = TextRun::text)
)
@Serializable
data class TextRun(val text: String)
}
Ok so this is what I have, but how would I fix it?
zt
11/05/2022, 4:30 AM
the json has a list of objects containing a text key
zt
11/05/2022, 4:36 AM
Would this be the correct way?
Copy code
@Serializable
internal class ApiText private constructor(private val runs: List<TextRun>) {
val text = runs.joinToString(separator = "", transform = TextRun::text)
@Serializable
data class TextRun(val text: String)
override fun toString() = text
}
android studio is saying
Constructor parameter is never used as a property
on the runs param
e
ephemient
11/05/2022, 4:43 AM
if that's how you want to use it then yes, that's the right way