-
Notifications
You must be signed in to change notification settings - Fork 620
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
Stabilize encoding and decoding of value classes #1963
Conversation
Part #1, serializers, encoders and decoders
core/commonMain/src/kotlinx/serialization/descriptors/SerialDescriptor.kt
Show resolved
Hide resolved
When we have this sorted out, I'll update the guide |
* because inline classes always have one property. | ||
* Calling [Encoder.beginStructure] on returned instance leads to an undefined behavior. | ||
* Note that this function returns [Encoder] instead of the [CompositeEncoder] | ||
* because value classes always have the single property. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just interesting: in future value classes will be able to have multiple properties (multi-field value classes KEEP) - how then kx.serialization will work with them?
Even if for now inline class
= value class
, may be it will be better consider in mind, that it will change.
And, f.e. introduce separate annotation like InlineSerializable
which will work not only with inline/value classes, but even with any other ordinary class or even interface?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how then kx.serialization will work with them
It's hard to tell without an actual design and implementation of multi-field value classes.
If the language will change the notion of value
classes, we will of course have to change these methods accordingly
I'm not sure it is the right approach just to do In my point of view, we should coin our definition of the words 'inline class' that would mean |
But this is not what this PR does! It is, in fact, already addresses most of your concerns. We still have all methods named "an underlying type of a value class in an inline manner" is exactly the terminology I aim for.
There isn't in our documentation. While we cannot foresee every potential language feature, here we can do an additional safety net and specify "encoding an underlying type of a value class with a single property in an inline manner.". Though, honestly, it may create a false perspective that there are value classes with multiple properties. I would rather add this "single property" clarification at the moment when multi-word value classes are started being worked on. |
core/commonMain/src/kotlinx/serialization/descriptors/SerialDescriptor.kt
Show resolved
Hide resolved
# Conflicts: # formats/json/commonMain/src/kotlinx/serialization/json/internal/StreamingJsonEncoder.kt
No description provided.