-
Notifications
You must be signed in to change notification settings - Fork 665
Description
What is your use-case and why do you need this feature?
Currently, kotlinx.serialization serializes all value classes as their property type. This works since only single-property value classes are supported. However, this is temporary, eventually multi-property value classes will be supported.
Serializing single-property and multi-property value classes differently in this way would be extremely unexpected and unintuitive.
Describe the solution you'd like
Value classes (the existing single-arg versions) should gradually stop being serialized in-place. This should be a gradual, backwards, compatible migration, like e.g. data class consistent copy visibility. Presumably that would mean first introducing an annotation to serialize non-in-place, then gradually deprecating it and making the behavior the default.
While this could in theory be based on @JvmInline, I don't think it's a good idea, since that's an implementation detail about how the class is represented, and doesn't really have any tie to the serial format. I also have no idea what the future of that annotation is in a post-Valhalla world. But I wouldn't want, for example, to not be able to migrate to using Valhalla single value value classes because I need this annotation for serialization.
Serializing in-place can be useful sometimes, it would be nice if there was an annotation to retain this behavior long term. At least for single-value value classes (although I see no reason to tie it to value classes).