-
Notifications
You must be signed in to change notification settings - Fork 619
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
Make makeNullable extension, make NullableSerializer internal #541
Conversation
qwwdfsad
commented
Aug 22, 2019
runtime/commonMain/src/kotlinx/serialization/internal/NullableSerializer.kt
Outdated
Show resolved
Hide resolved
runtime/commonMain/src/kotlinx/serialization/internal/NullableSerializer.kt
Show resolved
Hide resolved
runtime/commonMain/src/kotlinx/serialization/internal/NullableSerializer.kt
Outdated
Show resolved
Hide resolved
runtime/commonMain/src/kotlinx/serialization/internal/NullableSerializer.kt
Outdated
Show resolved
Hide resolved
*/ | ||
public val <T : Any> KSerializer<T>.nullable: KSerializer<T?> | ||
get() { | ||
return NullableSerializer(this) |
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.
One question. What happens if the receiver is already the NullableSerializer (or perhaps a custom serializer that handles nulls directly?). I don't think that nested NullableSerializers are correct for all formats (where notnullmark is actually used)
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.
Good point. Checking this.descriptor.isNullable
will also help to save some allocations.
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.
@qwwdfsad Could you take a look at this?
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.
Fixed.
I don't think that nested NullableSerializers are correct for all formats (where notnullmark is actually used)
It should be, if you know the case where this property doesn't hold, please report
runtime/commonMain/src/kotlinx/serialization/internal/NullableSerializer.kt
Show resolved
Hide resolved
*/ | ||
public val <T : Any> KSerializer<T>.nullable: KSerializer<T?> | ||
get() { | ||
return NullableSerializer(this) |
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.
@qwwdfsad Could you take a look at this?
* Introduced @InternalSerializationApi that provides no compatibility guarantees but is effectively public * Extension is more expressive, readable and is aligned with Kotlin conventions * NullableSerializer is an implementation detail and should not be exposed
ca1f770
to
4df8d10
Compare