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

SealedClassSerializer currently requires to OptIn to InternalSerializationApi #2721

Open
floschu opened this issue Jun 19, 2024 · 2 comments
Assignees
Labels

Comments

@floschu
Copy link

floschu commented Jun 19, 2024

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

We use SealedClassSerializer to manually generate KSerializers for sealed classes/sealed interfaces that are out of our scope and cannot be annotated with @Serializable and auto generate KSerializers.

This works currently and we use it, however we fear that due to the fact that it is an effective internal api, the implementation could change on a minor version release.
In the end, if this change would happen and would break our code, we could then still copy the internal code of the previous version and use it, but it would be nice to have a public way to manually do serialization of sealed classes. :)

Describe the solution you'd like

  1. Maybe there is something we are missing and there is a public way to serialize sealed classes which we have not found? 🤔
  2. If not, do not require SealedClassSerializer to OptIn to InternalSerializationApi.
@sandwwraith
Copy link
Member

No, there's currently no such way to write a sealed class hierarchy by hand. You're right, this feature is long overdue — see also #1865

@pdvrieze
Copy link
Contributor

Looking at this issue and #1865 what we are effectively doing is saying that we have a serializer that is somewhat polymorphic, but has a fixed set of subtypes defined by the serializer/serial descriptor rather than using a SerializersModule, independent of whether that type is actually sealed (per Kotlin).

Interesting to note is that the documentation for SEALED and OPEN actually mentions that the serializers are merely examples. This means that it must be possible to make things work without special treatment of SealedClassSerializer or PolymorphicSerializer. A custom serializer thus should be possible (I know generic buildSerialDescriptor is still experimental ;-), but not needed.

sandwwraith added a commit that referenced this issue Aug 7, 2024
This API has been around for a long time and has proven itself useful. The main reason @ExperimentalSerializationApi was on SerialDescriptor's properties is that we wanted to discourage people from subclassing it. With the introduction of @SubclassOptInRequired (#2366), we can do this without the need of marking everything with experimental.

Serial kinds fall into the same category with only exception in PolymorphicKind. There are plenty requests for functionality like creating a custom sealed-like descriptor (#2697, #2721, #1865) which may require additional kinds in the future.
qwwdfsad pushed a commit that referenced this issue Aug 26, 2024
This API has been around for a long time and has proven itself useful. The main reason @ExperimentalSerializationApi was on SerialDescriptor's properties is that we wanted to discourage people from subclassing it. With the introduction of @SubclassOptInRequired (#2366), we can do this without the need of marking everything with experimental.

Serial kinds fall into the same category with only exception in PolymorphicKind. There are plenty requests for functionality like creating a custom sealed-like descriptor (#2697, #2721, #1865) which may require additional kinds in the future.
sandwwraith added a commit that referenced this issue Aug 27, 2024
This API has been around for a long time and has proven itself useful. The main reason @ExperimentalSerializationApi was on SerialDescriptor's properties is that we wanted to discourage people from subclassing it. With the introduction of @SubclassOptInRequired (#2366), we can do this without the need of marking everything with experimental.

Serial kinds fall into the same category with only exception in PolymorphicKind. There are plenty requests for functionality like creating a custom sealed-like descriptor (#2697, #2721, #1865) which may require additional kinds in the future.
@sandwwraith sandwwraith self-assigned this Oct 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants