orchestr7/ktoml
View on GitHubContinue parsing on illegal value if default is present?
Open
#209 opened on Apr 14, 2023
enhancementgood first issuehelp wanted
Repository metrics
- Stars
- (561 stars)
- PR merge metrics
- (PR metrics pending)
Description
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.