```@Serializable data class Teaser( val text: ...
# serialization
z
Copy code
@Serializable
data class Teaser(
    val text: Text
) {
    @Serializable
    data class Text(val content: String)
}
How can I get rid of the boxing of text and be able to use it just like a string?
a
Copy code
@Serializable
@JvmInline
value class Text(val content: String)
do you mean like a value class? then you can do
Copy code
Json.decodeFromString<Teaser>("""
{
  "text": "blah blah"
}
""")
z
I wanna be able to decode this
Copy code
{
  "text": {
    "content": "g"
  }
}
to this
Copy code
Teaser(text=g)
m
Copy code
@Serializable
data class Teaser(
    @SerialName("text")
    val textObj: Text
) {
    constructor(text: String) : this(Text(text))

    @Transient // not sure if this is needed
    val text: String
        get() = textObj.content

    @Serializable
    data class Text(val content: String)
}
z
isn't this for just serializing? I only need deserializing
m
The
Serializable
annotation is for both serializing and deserializing
If you don't need serializing you can remove the secondary constructor from the code I posted