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

Annotation to ignore specific JSON keys

Open rnett opened this issue 1 year ago • 0 comments

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

I'm parsing JSON that I do not control, and which is not versioned or anything nice like that. Many of the fields are irrelevant to me, and thus, I would like to be able to ignore them. However, for the types I care about, I want errors to occur if the JSON adds new fields that I'm not explicitly handling, so the format-level ignoreUnknownKeys does not work for me. Some types (i.e. response boilerplate) I'd like to ignore any unknown fields.

Describe the solution you'd like

A class-level annotation to ignore some keys. For example @JsonIgnoreKeys(["unwanted_key", "another_unwanted_key") and @JsonIgnoreUnknownKeys (to ignore any unknown keys) annotations that could be applied to classes.

rnett avatar Jan 16 '24 00:01 rnett