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
classTomlReadTest : FunSpec({
test("toml read nullable") {
@Serializable
data class Key(val value: Long)
@Serializable
data class Config(val key: Key?)
val mapper = Toml(
config = KtomlConf(
ignoreUnknownNames = true,
emptyValuesAllowed = true
)
)
val toml = mapper.decodeFromString<Config>("""
[key]
value = 1
""".trimIndent())
assertNotNull(toml)
assertEquals(1L, toml.key?.value)
}
})
It is expected to deserialize Config with key = Key(1L), however ktoml fails with:
This kind of node should not be processed in TomlDecoder.decodeValue(): com.akuleshov7.ktoml.parsers.node.TomlTable@6d9c9c74
com.akuleshov7.ktoml.exceptions.InternalDecodingException: This kind of node should not be processed in TomlDecoder.decodeValue(): com.akuleshov7.ktoml.parsers.node.TomlTable@6d9c9c74
at com.akuleshov7.ktoml.decoders.TomlDecoder.decodeKeyValue(TomlDecoder.kt:96)
at com.akuleshov7.ktoml.decoders.TomlDecoder.decodeValue(TomlDecoder.kt:25)
at com.akuleshov7.ktoml.decoders.TomlDecoder.decodeNotNullMark(TomlDecoder.kt:36)
at kotlinx.serialization.encoding.AbstractDecoder.decodeNullableSerializableElement(AbstractDecoder.kt:79)
Changing to a property with default value does work:
classTomlReadTest : FunSpec({
test("toml read nullable") {
@Serializable
data class Key(val value: Long)
@Serializable
data class Config(val key: Key = Key(0L))
val mapper = Toml(
config = KtomlConf(
ignoreUnknownNames = true,
emptyValuesAllowed = true
)
)
val toml = mapper.decodeFromString<Config>("""
[key]
value = 1
""".trimIndent())
assertNotNull(toml)
assertEquals(1L, toml.key.value)
}
})
All my code base uses Kotlinx Serialization, only the configuration parsing is using Jackson and I would like to remove this.
The text was updated successfully, but these errors were encountered:
Hello @JonathanxD! Thank you for this issue! I even did not think that someone will use a nullable table… I will try to support it in the nearest release.
But it looks that I will need to change the logic significantly.
PS I am actually confused that the default value for tables worked. I have supported it by chance🤦♂️
Given the following code:
It is expected to deserialize
Config
withkey = Key(1L)
, however ktoml fails with:Changing to a property with default value does work:
All my code base uses Kotlinx Serialization, only the configuration parsing is using Jackson and I would like to remove this.
The text was updated successfully, but these errors were encountered: