Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

json: Use @SerialName of inline polymorphic children #2601

Merged
merged 2 commits into from Mar 25, 2024

Conversation

tadfisher
Copy link

Fixes #2288

Currently, the serialName of value class children of sealed classes is ignored for encoding. Fix this in by storing the child's serialName in encodeInline, and consuming it in beginStructure. A small fix was needed to support decoding these types in JsonTreeDecoder.

@tadfisher tadfisher force-pushed the tad/sealed-inline-serialname branch from 2eab64f to ca6d783 Compare March 14, 2024 02:05
Copy link
Contributor

@pdvrieze pdvrieze left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some comments on the code

@@ -35,7 +35,8 @@ internal fun <T> Json.readPolymorphicJson(

private sealed class AbstractJsonTreeDecoder(
override val json: Json,
open val value: JsonElement
open val value: JsonElement,
protected val polyDiscriminator: String? = null
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Be consistent in naming, in other places it is called polymorphicDiscriminator

Copy link
Author

@tadfisher tadfisher Mar 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you like me to rename polyDescriptor (the following parameter in JsonTreeDecoder) as well? I was trying to be consistent with that.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Full name (polymorphicDiscriminator) is better

@tadfisher tadfisher force-pushed the tad/sealed-inline-serialname branch from ca6d783 to edcf14e Compare March 14, 2024 18:02
Copy link
Member

@sandwwraith sandwwraith left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for PR! I do not have further comments, but can you rebase it on dev and open it against that branch, please?

@tadfisher tadfisher force-pushed the tad/sealed-inline-serialname branch from edcf14e to a3f54a7 Compare March 21, 2024 21:08
@tadfisher tadfisher force-pushed the tad/sealed-inline-serialname branch from a3f54a7 to 9854e11 Compare March 21, 2024 21:08
@tadfisher tadfisher changed the base branch from master to dev March 21, 2024 21:08
@tadfisher
Copy link
Author

@sandwwraith Done!

Copy link
Member

@sandwwraith sandwwraith left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job!

@sandwwraith sandwwraith merged commit f242bb5 into Kotlin:dev Mar 25, 2024
3 checks passed
@sandwwraith
Copy link
Member

Note to self: it doesn't fix related problems with custom serializers (e.g. #2596), as they have different code path, so further investigation is required

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.

Mismatch in deserialized/serialized serial name used for sealed value class.
3 participants