-
Notifications
You must be signed in to change notification settings - Fork 628
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
If a data class has a List parameter, default value emptyList()
, encode to string does not return empty json array
#1447
Comments
Set
HTH! Cheers. p.s. I have tested it & it worked as expected (on my machine). |
Thanks, but that results in the In the example test I posted, if I add encodeDefaults private val jsonFormatter = Json {
prettyPrint = true
encodeDefaults = true
} Then both tests fail Cat:
Dog:
I am expecting that val pet = Dog(
name = "Fido",
tags = emptyList(),
) should have a json path Instead, I only get
|
This might be of interest then. #195 |
Providing |
I think this has been resolved by #1091 - thanks! |
Describe the bug
Given a data class with a parameter
List<String>?
which has a default value ofemptyList()
, when an instance of that class is encoded to string, then the field is not included in the resulting json - the field is missing. An empty json array[]
was expected.Expected:
{"name":"Fido", "tags":[]}
Actual:
{"name":"Fido"}
Note that if the
List<String>?
parameter has a default ofnull
, and when it is created it is set toemptyList()
, thenencodeToString(...)
works correctly, and an empty json array is produced.To Reproduce
Environment
The text was updated successfully, but these errors were encountered: