akuleshov7 / ktoml

Kotlin Multiplatform parser and compile-time serializer/deserializer for TOML format (Native, JS, JVM) based on KxS

Home Page:https://akuleshov7.github.io/ktoml

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Char encoding error

chabapok opened this issue · comments

If we try encode Char, it encoded with double quotes. If we try to decode, it fails. Decoder wants single-quoted chars:

@Serializable
data class Foo(val foo: Char= 'x')

fun main(){
    val s = Toml().encodeToString(Foo('f'))
    println(s) // foo = "f"

    // decode exception
    val config = Toml().decodeFromString<Foo>(s)

    // single-quoted decoded ok
    Toml().decodeFromString<Foo>("doo='f'")
}

Thanks for this report!

@chabapok, As per the TOML specification, there is no predefined Char type. However, we've introduced the concept in our TOML implementation to align more closely with Kotlin's syntax. So we are expecting Chars to have single quote on the decoding.

Probably we need to make it more convenient and do encoding and decoding similar.

Will fix it, thanks!