Skip to content

Allow creation of custom polymorphic descriptor #1411

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

Closed
diesieben07 opened this issue Apr 9, 2021 · 3 comments
Closed

Allow creation of custom polymorphic descriptor #1411

diesieben07 opened this issue Apr 9, 2021 · 3 comments

Comments

@diesieben07
Copy link

What is your use-case and why do you need this feature?
I am using JsonContentPolymorphicSerializer to deserialize JSON similar to the following:
Either:

{
  "$ref": "<some URI>"
}

or

{
   "actual": "data"
}

I'd like to improve the default descriptor provided by JsonContentPolymorphicSerializer, similar to the one provided by SealedClassSerializer. However it is currently impossible to construct a SerialDescriptor other than StructureKind.CLASS or primitive without using the internal API buildSerialDescriptor, which states:

If you end up using this builder, please file an issue with your use-case in kotlinx.serialization

Describe the solution you'd like
A SerialDescriptor builder for PolymorphicKind.SEALED similar to buildSerialDescriptor.

@sandwwraith
Copy link
Member

Currently, SEALED class descriptor has a requirement to contain all possible variants descriptors. I assume you can fulfil this requirement, since you know what serializers you are going to use statically, so it's possible to use internal API to mimic SealedClassSerializer's descriptor.

Why do you need this exact SEALED kind? Are you using something like a schema generator? This kind is not used in a regular serialization for now

@diesieben07
Copy link
Author

diesieben07 commented Apr 13, 2021

Yes, I know all the possible serializers statically.

Why do you need this exact SEALED kind? Are you using something like a schema generator? This kind is not used in a regular serialization for now

Because JsonContentPolymorphicSerializer says you can do so in its docs. However there is no way to do so without using the internal buildSerialDescriptor API.
Either the docs should be changed and descriptor made final or there should be a way to do as the docs say.

@sandwwraith
Copy link
Member

Will be handled as a part of #1775 and #2460

@sandwwraith sandwwraith closed this as not planned Won't fix, can't repro, duplicate, stale Dec 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants