Skip to content

Parse nullable properties with non-default values when the keys are not present in the Json #1024

Closed
@eliekarouz

Description

@eliekarouz

What is your use-case and why do you need this feature?

Ability to parse nullable properties when the keys are not present in the JSON.

@kotlinx.serialization.Serializable
data class Foo(val foo: String?)

Trying to parse this JSON string {} fails.

The current workaround would be to add a default value val foo: String? = null. However, we don't always have access to the entities in order to apply the fix. One example is when trying to create external serializers for the SqlDelight autogenerated entities.

Describe the solution you'd like
Add a configuration acceptNonPresentKeys which when set to true, the parser would automatically produce
Foo(foo = null) when {} this is provided.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions