Skip to content

Provide ignoreUnknownKeys for CBOR decoding #935

@twyatt

Description

@twyatt

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

If a remote endpoint is updated to add field(s) then client will fail.

This becomes particularly cumbersome with Android where users may continue to run an older version of an app for some time. Ideally, the remote endpoint that the Android app communicates with could add new fields to a CBOR payload and updated apps could read the new field (to support new functionality) while older versions of the app just silently ignore the new fields.

For example, if we had the following definition in a client:

@Serializable
data class Example(
    val a: String
)

If remote endpoint was updated to add the field b:

  BF           # map(*)
     61        # text(1)
        61     # "a"
     63        # text(3)
        313233 # "123"
+    61        # text(1)
+       62     # "b"
+    63        # text(3)
+       393837 # "987"
     FF        # primitive(*)

Then clients will fail with:

kotlinx.serialization.SerializationException: Example does not contain element with name 'b'

Describe the solution you'd like

JSON deserialization provides the ignoreUnknownKeys option which allows the encoded JSON to contain fields that are absent in the Kotlin class definition.

Ideally, CBOR decoding could also be configured with ignoreUnknownKeys (or similar) option.

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