when using a private constructor then a public con...
# serialization
z
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
kotlinx.serialization uses the primary constructor. if you mean something like
Copy code
@Serializable
class Foo private constructor(
    ...
) {
    constructor(...) : this(..)
}
then it's using the private constructor, not the public constructor
z
e
in that example, "Serialization works with a private primary constructor"
what is the other way around about it?
z
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?
the json has a list of objects containing a text key
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
if that's how you want to use it then yes, that's the right way