Skip to content

Skip discriminator entries when decoding inline-map sealed children#3173

Open
tadfisher wants to merge 1 commit intoKotlin:devfrom
tadfisher:tad/sealed-inline-map
Open

Skip discriminator entries when decoding inline-map sealed children#3173
tadfisher wants to merge 1 commit intoKotlin:devfrom
tadfisher:tad/sealed-inline-map

Conversation

@tadfisher
Copy link
Copy Markdown
Contributor

Fixes #3172

Streaming JSON decoding is missing an edge-case where:

  • an object is decoded in MAP mode
  • the object contains a polymorphic discriminator

I believe the only case this can happen is when you have a value class, wrapping Map<K, V>, in a sealed hierarchy. If we're in this case, skip the discriminator entry and proceed to decode the object as a Map.

Tree decoding doesn't handle the discriminator either; skip it by filtering it out of keys.

There's an ancillary issue the test revealed: encoding the value class with JsonTreeEncoder is missing the discriminator entirely, probably because we don't set a tag for Map values. Added similar handling for the case where we have a discriminator but no tag, and return this decoder so that we encode the wrapped value without dealing with tags.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant