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

Continue parsing on illegal value if default is present?

wefhy opened this issue · comments

commented

Is there any way to continue parsing the rest of the file if one of the values is of wrong type but the class contains default value for it?
For example when some enum is misspelled

code example:

enum class EnumTest { A, B, C }
@Serializable
data class Foo(
    val a: Int = 5,
    val b: EnumTest = EnumTest.A,
    val c: String = "hello"
)

TOML:

a = 8
b = "D"
c = "world"

Expected result of parsing would be
Foo(a = 8, b = EnumTest.A, c = "world")

Current behavior:
Value <D> is not a valid enum option. Permitted choices are: A, B, C

My current workaround is to catch the exception, remove the line with specified value and try to parse again. But even that fails if that wrong value is correctly used in another place in the file.

Hm, very unusual case for us, but probably we need to think about such an option to have non-strict parsing in case when the default value is already provided