You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
class CustomSerializerTest {
object ColorAsStringSerializer : KSerializer<Color> {
override val descriptor: SerialDescriptor = PrimitiveSerialDescriptor("Color", PrimitiveKind.STRING)
override fun serialize(encoder: Encoder, value: Color) {
TODO()
}
override fun deserialize(decoder: Decoder): Color {
val value = decoder.decodeString()
return Color(value.toLong())
}
}
@Serializable(with = ColorAsStringSerializer::class)
data class Color(val rgb: Long)
@Serializable
data class Settings(val background: Color, val foreground: Color)
@Test
fun testDecodingWithCustomSerializer() {
println(Toml.decodeFromString<Settings>(
"""
[background]
rgb = 0
[foreground]
rgb = 0
""".trimIndent()
))
}
}
will cause
This kind of node should not be processed in TomlDecoder.decodeValue(): [background]
com.akuleshov7.ktoml.exceptions.InternalDecodingException: This kind of node should not be processed in TomlDecoder.decodeValue(): [background]
at app//com.akuleshov7.ktoml.decoders.TomlMainDecoder.decodeKeyValue$ktoml_core(TomlMainDecoder.kt:84)
at app//com.akuleshov7.ktoml.decoders.TomlAbstractDecoder.decodeString(TomlAbstractDecoder.kt:101)
at app//com.akuleshov7.ktoml.decoders.CustomSerializerTest$ColorAsStringSerializer.deserialize(CustomSerializerTest.kt:23)
at app//com.akuleshov7.ktoml.decoders.CustomSerializerTest$ColorAsStringSerializer.deserialize(CustomSerializerTest.kt:15)
at app//kotlinx.serialization.encoding.Decoder$DefaultImpls.decodeSerializableValue(Decoding.kt:260)
at app//kotlinx.serialization.encoding.AbstractDecoder.decodeSerializableValue(AbstractDecoder.kt:16)
The text was updated successfully, but these errors were encountered:
will cause
The text was updated successfully, but these errors were encountered: