Disable explicit nulls for JSON serializer
See original GitHub issueDescribe your suggested feature
https://github.com/Kotlin/kotlinx.serialization/blob/master/docs/json.md#explicit-nulls
- Json { ignoreUnknownKeys = true }
+ Json { ignoreUnknownKeys = true; explicitNulls = false }
Disabling explicit nulls enables people to write field: String?
instead of field: String? = null
when creating DTO classes for extensions (without creating another instance of Json). Having to write the default null
is kinda unnecessary in my opinion since people rarely create instances of those manually.
This can avoid unnecessary errors when people forget to write the default null
. These cases can be hard to test because:
- Tested manga list pages or manga details might happen to contain all those fields. The specific entry that omitted these fields (that the extension developer has seen when testing the API) might be un-tested in the app.
- Some websites have different behavior (either supply
null
or omit field) for the same model across different API endpoints, or even different entries. This might fool people into writingString?
confidently on seeing the API returning"field": null
for one specific response.
However people should not depend on this change until the next extension-lib update.
Other details
No response
Acknowledgements
- I have searched the existing issues and this is a new ticket, NOT a duplicate or related to another open or closed issue.
- I have written a short but informative title.
- If this is an issue with an extension, I should be opening an issue in the extensions repository.
- I have updated the app to version 0.13.6.
- I will fill out all of the requested information in this form.
Issue Analytics
- State:
- Created a year ago
- Comments:5 (5 by maintainers)
Top Results From Across the Web
How to ignore a property in class if null, using json.net
You can do this to ignore all nulls in an object you're serializing, and any null properties won't then appear in the JSON...
Read more >Allow to always ignore nulls and empty collections ... - GitHub
I'm currently searching for a solution where null values will not be part of the json, but I want to have other default...
Read more >explicitNulls - Kotlin
explicitNulls ... Specifies whether null values should be encoded for nullable properties and must be present in JSON object during decoding. When this...
Read more >C# 8.0 nullable references and serialization - Endjin
C# 8's nullable references feature can clash with common serialization techniques. This article shows how to deal with that.
Read more >JsonSerializerOptions.IgnoreNullValues Property
Gets or sets a value that indicates whether null values are ignored during serialization and deserialization. The default value is false.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
It’s generally fine to only support the latest stable version (with a bit of delay so people can update first), but the relevant changes also need to be communicated to the main fork devs to ensure they also have stable releases too.
My consideration is that relying on the latest stable release might break compability with older working versions or other forks. It’s safest to bind the change with a new lib version so that all versions that implement the new lib can work with extensions flawlessly.