-
Notifications
You must be signed in to change notification settings - Fork 623
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
feat: Make SerialDescriptorForNullable.original public #2633
feat: Make SerialDescriptorForNullable.original public #2633
Conversation
2532763
to
e555fdf
Compare
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.
You should also do a couple more things:
- Update public API dump (see https://github.com/Kotlin/kotlinx.serialization/blob/master/CONTRIBUTING.md#updating-the-public-api-dump)
- Add some tests for the change — that
x.nullable.unwrapNullable === x
, that for@Serializable class X(val s: String?)
,val n = X.serializer().descriptor.getElementDescriptor(0)
results inn.isNullable == true
andn.unwrapNullable == String.serializer().descriptor
, for your use case, etc.
core/commonMain/src/kotlinx/serialization/descriptors/SerialDescriptors.kt
Outdated
Show resolved
Hide resolved
core/commonMain/src/kotlinx/serialization/descriptors/SerialDescriptors.kt
Outdated
Show resolved
Hide resolved
39e8694
to
5d22d74
Compare
Following the contributing guide, I've rebased onto |
* @see KSerializer.nullable | ||
*/ | ||
@ExperimentalSerializationApi | ||
public val SerialDescriptor.unwrapNullable: SerialDescriptor |
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.
After looking at the api dump, I've realized that unwrap
is actually a verb, and its counter-intuitive to have a verb in property name (https://kotlinlang.org/docs/coding-conventions.html#choose-good-names). So it should be either
- A function
SerialDescriptor.unwrapNullable()
or - A property with a noun, e.g.
unwrappedNullable
.
I'm not sure what is better. Doing (1) will bring asymmetry with .nullable
. (2) is confusing, because it is not clear what 'unwrapped' is since we do not have 'wrapped' anywhere else. Besides, 'unwrappedNullable' sounds like some flavor of a nullable thing, but in reality, returned descriptor may be non-nullable.
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.
You're right, I'm feeling the same. I would prefer unwrappedNullable
to not have this asymmetry. I'll commit now. If you feel not comfortable, could we have a third person reviewing this to help chosing a better name ?
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.
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.
Or, we can do unwrappedOriginal
and also unwrap WrappedSerialDescriptor.original
(I've looked at all the SerialDescriptors and only SerialDescriptorForNullable and WrappedSerialDescriptor would have sense of unwrapping the original descriptor)
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.
@Chuckame It seems to be that the route of introducing a WrappedSerialDescriptor
interface would make a lot of sense, it would also future proof the design to support other wrapping descriptors (and not special case the nullable descriptor only)
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.
I like the idea, but it would mean also renaming the current data class WrappedSerialDescriptor
to something else to allow creation of the interface. What do you think @sandwwraith ?
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.
the route of introducing a WrappedSerialDescriptor interface would make a lot of sense, it would also future proof the design to support other wrapping descriptors
IMO this is way out of scope of this PR.
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.
WDYT of nonNullableOriginal
name? We can add to the documentation that this property "does not affect descriptors that were created as nullable by directly implementing SerialDescriptor 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.
New doc, is it okay for you @sandwwraith ? I also renamed to nonNullOriginal
(pushed)
* Returns non-nullable serial descriptor for the type, only if this descriptor has been auto-generated (plugin
* generated descriptors) or with `.nullable` extension on a descriptor or serializer.
*
* Otherwise, returns this.
*
* It may return nullable descriptor if this descriptor has been created manually as nullable by directly implementing SerialDescriptor interface.
*
7a82e70
to
5d96ac7
Compare
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.
Yep, looks good to me
core/commonMain/src/kotlinx/serialization/descriptors/SerialDescriptors.kt
Outdated
Show resolved
Hide resolved
core/commonMain/src/kotlinx/serialization/descriptors/SerialDescriptors.kt
Outdated
Show resolved
Hide resolved
@Chuckame You need to update apiDump with tool: |
588a5ae
to
56b5c50
Compare
@sandwwraith it's ready, apiDump done, doc updated. When do you think it could be released ? |
@Chuckame We usually do releases around Kotlin's release. Given that 2.0.0 is just around the corner, I think it will be in about a month. |
Ok thanks, so I'll wait this PR release before releasing on my side. |
Thank you! |
Can I access to a snapshot build until the release ? |
Unfortunately, we don't do snapshot builds. You can build it yourself and publish it to your maven local (https://github.com/Kotlin/kotlinx.serialization/blob/master/docs/building.md) if you want to test the changes with your library |
Closes #2631