kotlinx.serialization icon indicating copy to clipboard operation
kotlinx.serialization copied to clipboard

Separate Invalid Enum Names to Default & Null to Default

Open Laxystem opened this issue 2 years ago • 1 comments

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

I am working on an API, using ktor - and I've noticed the coerceInputValues config option.

On one hand, it allows us to make providing null equal to not providing anything at all (together with the explicitNulls option) in our API. To us, providing null means "no change than default", making it a valid input.

On the other hand, it turns invalid enum entries to the default - which can cause annoying, hard to fix bugs on the user's side.

Describe the solution you'd like

Separate it to two, different, config options.

Laxystem avatar Aug 26 '23 17:08 Laxystem

We had similar concerns while developing this feature, but it turns out that this is an unpopular use case. I can recommend you omitting values instead of sending nulls to keep defaults. It will also help with schema evolution — e.g., if you make property nullable, you won't suddenly start seeing nulls. Also, you would be able to differentiate new enum values from incorrect ones.

sandwwraith avatar Sep 12 '23 11:09 sandwwraith