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

Protobuf skip null fields #590

Closed
wants to merge 10 commits into from
Closed

Conversation

bezmax
Copy link

@bezmax bezmax commented Oct 31, 2019

Resubmission of #588

The issue blocks any real usage of kotlinx.serialization, as there is no way to serialize an optional field as of right now. I suggest this as an easy and mostly-compatible fix until a long-term solution is devised.

The solution here introduces separate TaggedEncoder#shouldWriteNullElement method, which can be overriden by different Encoders to provide custom null-handling behaviour. For this PR only ProtoBufEncoder overrides it to skip null CLASS type fields (as should be completely compatible with Proto spec).

Other encoders could also benefit from this, for example an extra setting could be added to JSON encoder to skip null fields altogether.

@bezmax bezmax closed this Oct 31, 2019
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.

7 participants