Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Continue parsing on illegal value if default is present? #209

Open
wefhy opened this issue Apr 14, 2023 · 1 comment
Open

Continue parsing on illegal value if default is present? #209

wefhy opened this issue Apr 14, 2023 · 1 comment
Assignees
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed

Comments

@wefhy
Copy link

wefhy commented Apr 14, 2023

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.

@orchestr7
Copy link
Owner

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

@orchestr7 orchestr7 self-assigned this Apr 15, 2023
@orchestr7 orchestr7 added enhancement New feature or request help wanted Extra attention is needed good first issue Good for newcomers labels Apr 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants