-
Notifications
You must be signed in to change notification settings - Fork 60
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
Add encoding option to specify how omitempty fields are encoded #453
Conversation
The current behavior in the library is to omits if field value would encode as empty JSON value. This behavior is different from the bahavior in golang encoding/json which omits if field value is an empty Go value (defined as false, 0, a nil pointer, a nil interface value, and any empty array, slice, map, or string). The OmitEmptyMode = 1 is added to encoding option so that cbor would decode omitempty fields similarly to encoding/json in go. Signed-off-by: Vu Dinh <[email protected]>
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.
@dinhxuanvu Thanks for opening this PR! 👍
I left some feedback for your consideration and will try to include this PR in v2.6.0 if possible.
Thanks again!
@fxamacker Thanks so much for the feedbacks. All are addressed! PTAL |
Signed-off-by: Vu Dinh <[email protected]>
96d9a46
to
f95914b
Compare
Force-pushed to fix a small fix with lint (variable name). |
@dinhxuanvu Thanks for opening issue and contributing this PR! 👍 I'd like to include this in v2.6 and will take a closer look this weekend! |
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.
@dinhxuanvu Thanks for updating the PR! LGTM! 👍
Description
The current behavior in the library is to omits if field value would encode as empty JSON value. This behavior is different from the bahavior in golang encoding/json which omits if field value is an empty Go value (defined as false, 0, a nil pointer, a nil interface value, and any empty array, slice, map, or string). The OmitEmptyMode = 1 is added to encoding option so that cbor would decode omitempty fields similarly to encoding/json in go.
PR Was Proposed and Welcomed in Currently Open Issue
Checklist (for code PR only, ignore for docs PR)
Last line of each commit message should be in this format:
Signed-off-by: Firstname Lastname [email protected]
(see next section).
Certify the Developer's Certificate of Origin 1.1
the Developer Certificate of Origin 1.1.