LastExceed
06/11/2021, 6:03 AMa unique name of the type that is being serialized
but i dont understand what that means
also why does Line 2 work but Line 3 break ?ephemient
06/11/2021, 6:32 AMFruit.Companion.serializer()
, so the reflection-based serializer lookup doesn't workephemient
06/11/2021, 6:33 AMephemient
06/11/2021, 6:33 AMJson.encodeToString(FruitAsIntSerializer, Fruit.Apple)
will workLastExceed
06/11/2021, 6:34 AMephemient
06/11/2021, 6:38 AMephemient
06/11/2021, 6:38 AMval json = Json {
serializersModule = SerializersModule {
contextual(FruitAsIntSerializer)
}
}
json.encodeToString(Fruit.Apple)
also worksLastExceed
06/11/2021, 6:40 AMcompanion object {
fun serializer() = FruitAsIntSerializer
}
this seems to work as well, though im not sure if i should rely on thatLastExceed
06/11/2021, 6:43 AMephemient
06/11/2021, 6:44 AMfun serializer()
is explicitly not supportedLastExceed
06/11/2021, 6:45 AMYou cannot define your own functionwell apparently i can lolon a companion object of a serializable classserializer()
ephemient
06/11/2021, 6:47 AM@Serializable
-generated serializersephemient
06/11/2021, 6:47 AMwell apparently i can lolfor now… no guarantees.
LastExceed
06/11/2021, 6:49 AM@Serializable
annotation generates the function in the companion object. then shouldnt it also generate fun serializer() = FruitAsIntSerializer
when i use @Serializable(FruitAsIntSerializer::class
?ephemient
06/11/2021, 6:55 AMLastExceed
06/11/2021, 6:56 AMfun serializer() = FruitAsIntSerializer
keeps working until its getting autogeneratedephemient
06/11/2021, 6:56 AMLastExceed
06/11/2021, 6:58 AMephemient
06/11/2021, 6:58 AMenum class Fruit constructor(val serializedForm: Int) {
Apple(1),
Banana(2)
}
@Serializer(forClass = Fruit::class)
object FruitAsIntSerializer : KSerializer<Fruit>
will work tooephemient
06/11/2021, 6:59 AMephemient
06/11/2021, 7:00 AMdeserialize
function is bad: Json.decodeFromString<Fruit>("2")
will failephemient
06/11/2021, 7:00 AMdecodeInt()
exactly onceLastExceed
06/11/2021, 7:01 AM@Serializer(forClass = Fruit::class)
didnt work
next version of Kotlindarn
will failJson.decodeFromString<Fruit>("2")
2
is an invalid valueLastExceed
06/11/2021, 7:02 AMephemient
06/11/2021, 7:04 AM@Serializer(forClass =)
suggestion, that doesn't get looked up the way I thought it didLastExceed
06/11/2021, 7:04 AMLastExceed
06/11/2021, 7:06 AMmaster
branch already, dont think they'd do that if it's for 1.6ephemient
06/11/2021, 7:06 AMLastExceed
06/11/2021, 7:07 AMephemient
06/11/2021, 7:07 AM