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

Make makeNullable extension, make NullableSerializer internal #541

Merged
merged 1 commit into from
Sep 10, 2019

Conversation

qwwdfsad
Copy link
Collaborator

* Extension is more expressive, readable and is aligned with Kotlin conventions
* NullableSerializer is an implementation detail and should not be exposed

*/
public val <T : Any> KSerializer<T>.nullable: KSerializer<T?>
get() {
return NullableSerializer(this)
Copy link
Contributor

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)

Copy link
Member

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.

Copy link
Member

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?

Copy link
Collaborator Author

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

build.gradle Show resolved Hide resolved
*/
public val <T : Any> KSerializer<T>.nullable: KSerializer<T?>
get() {
return NullableSerializer(this)
Copy link
Member

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
@qwwdfsad qwwdfsad merged commit 0d830ae into dev Sep 10, 2019
@qwwdfsad qwwdfsad deleted the nullable-ext branch September 10, 2019 15:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants