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

Null values are improperly serialized #72

Open
sproctor opened this issue Oct 25, 2021 · 4 comments
Open

Null values are improperly serialized #72

sproctor opened this issue Oct 25, 2021 · 4 comments
Labels

Comments

@sproctor
Copy link

Data classes with null property values are serialized with those values as a string literal with a value of "null" instead a null literal. Jackson then attempts to de-serialize the string literal to the type of the property.

Caused by: com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot construct instance of `CustomChildType` (although at least one Creator exists): no String-argument constructor/factory method to deserialize from String value ('null')
@uchuhimo
Copy link
Owner

@sproctor Can you provide a test case for me to reproduce the issue? I will try to fix it.

@sproctor
Copy link
Author

Something like:

object ExampleSpec : ConfigSpec {
    val foo by optional(Foo(null))
}

data class Foo(val bar: Bar?)
data class Bar(val baz: String)

I didn't do a lot of digging to see if null values other than data classes cause the issue.

The output from that is:

 {
   "example" : {
     "foo" : {
       "bar" : "null"
     }
   }
 }

It should be:

 {
   "example" : {
     "foo" : {
       "bar" : null
     }
   }
 }

Changing the config file manually fixes the issue until the next time it's saved.

@sproctor
Copy link
Author

Sorry, this was way more complicated than necessary. String? exhibits the same behavior.

object ExampleSpec : ConfigSpec {
    val foo by optional<String?>(null)
}

That will store the null with quotes instead of as a null literal. I just didn't notice the issue there because it deserializes to the string "null" instead of a null value, but doesn't cause a crash.

@sproctor sproctor changed the title Null values cannot be de-serialized Null values are improperly serialized Oct 26, 2021
@stale
Copy link

stale bot commented Apr 16, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed after 30 days if no further activity occurs, but feel free to re-open a closed issue if needed.

@stale stale bot added the stale label Apr 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants