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

~ can not be used as a replacement for null #149

Closed
BloodWorkXGaming opened this issue Jun 13, 2021 · 3 comments
Closed

~ can not be used as a replacement for null #149

BloodWorkXGaming opened this issue Jun 13, 2021 · 3 comments
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@BloodWorkXGaming
Copy link

I just noticed that if you have a nullable list like

@Serializable
data class TestClass(
    val n: List<String>? = null
)

and you try to read it with

val yaml =
            """
            n: ~
        """.trimIndent()

        val obj = Yaml.default.decodeFromString<TestClass>(yaml)

It fails with the exception:

Value for 'n' is invalid: Expected a list, but got a scalar value
com.charleskorn.kaml.InvalidPropertyValueException at n on line 2, column 4: Value for 'n' is invalid: Expected a list, but got a scalar value
@BloodWorkXGaming
Copy link
Author

Looking further at the spec, I figured out that ~ is only supported in the Core spec, not the JSON spec.
Which spec is this library targeting?
https://yaml.org/spec/1.2/spec.html#Schema

@charleskorn
Copy link
Owner

Thanks for the report @BloodWorkXGaming, you're correct - ~ should be treated as a null value. In the JSON schema, null is the canonical form (so null should be emitted by default), but this should not impact parsing.

Would you be interested in submitting a PR to fix this issue? https://github.com/charleskorn/kaml/blob/main/src/jvmMain/kotlin/com/charleskorn/kaml/YamlNodeReader.kt#L64 looks like the right place for this fix (+ adding some tests, of course :) )

@charleskorn charleskorn added bug Something isn't working good first issue Good for newcomers labels Jun 14, 2021
@BloodWorkXGaming
Copy link
Author

Yes, thank you, that looks pretty straight forward to fix. Will try to fix it and open a new PR :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants