There are treated as the underlying value. Do you have a test?
c
Cies Breijs
10/22/2025, 11:28 AM
Absolutely right.. I encountered this using terpal-sql and thought it was a due to kotlinx.serialization... My bad. I'm deleting this thread in a bit so no-one needs to be bothered by it.
Thanks for chiming in!
Here the test:
Copy code
import kotlinx.serialization.Serializable
import kotlinx.serialization.json.Json
@JvmInline
@Serializable
value class ProductId(val value: Long)
@Serializable
data class ProductDto(
val id: ProductId,
val name: String
)
fun main() {
val d = Json.decodeFromString<ProductDto>("""{"id": 1000, "name": "qweqw"}""")
println(d) // ProductDto(id=ProductId(value=1000), name=qweqw)
val s = Json.encodeToString(d)
println(s) // {"id":1000,"name":"qweqw"}
}