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

Allow (de-)serializing value classes if their backing property is serializable #2732

Closed
Martmists-GH opened this issue Jun 29, 2024 · 1 comment
Labels

Comments

@Martmists-GH
Copy link

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

For example, in Compose code, one might want to save the user's custom theme by serializing Colors. These are defined as value class Color(value: ULong) which should be trivial to (de-)serialize, as value classes guarantee a single-argument constructor and a single field to handle.

Describe the solution you'd like

Value classes are serialized as if serialize(myXTypeValue.value) was called, and deserialized like XType(deserialize(encValue))

@sandwwraith
Copy link
Member

Even if the property is serializable, we still need the value class Color to be marked as @Serializable too. This comes from the fact that in constructions like List<Color> actual boxing happens (i.e. instantiation of a new Color instance, not just ULong). And to properly serialize/deserialize the class instance, a corresponding serializer have to be generated, since we can't write one serializer to deserialize all possible value classes — that's not how the compiler plugin works

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

2 participants