[GODRIVER-1229] Laxing bson "omitempty" Created: 12/Aug/19  Updated: 27/Feb/23  Resolved: 27/Feb/23

Status: Closed
Project: Go Driver
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Improvement Priority: Major - P3
Reporter: khoa pham Assignee: Unassigned
Resolution: Cannot Reproduce Votes: 0
Labels: mgocompat
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Documentation Changes Summary:

1. What would you like to communicate to the user about this feature?
2. Would you like the user to see examples of the syntax and/or executable code and its output?
3. Which versions of the driver/connector does this apply to?


 Description   

This is from golang std json:

The "omitempty" option specifies that the field should be omitted from the encoding if the field has an empty value, defined as false, 0, a nil pointer, a nil interface value, and any empty array, slice, map, or string.

bson "omitempty" tag should do the same behavior as json so that we could reduce the number of pointers in decoding struct types.

Example:

struct below

type xyz struct {
	Test string `bson:"test,omitempty"`
}

won't work with this "bson" data:

{"test":null}

but will work fine with golang std json: https://play.golang.org/p/q-Wnr81Pu3b



 Comments   
Comment by Matt Dale [ 27/Feb/23 ]

I'm unable to reproduce this issue using the latest version of the Go Driver BSON library (v1.11.2) See an attempt at reproducing it here: https://go.dev/play/p/jkHO0lzDljq

Closing this as can't reproduce.

Generated at Thu Feb 08 08:35:57 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.