[GODRIVER-1175] allow BSON null values to decode into non-nilable Go types Created: 01/Jul/19 Updated: 28/Oct/23 Resolved: 30/Jan/20 |
|
| Status: | Closed |
| Project: | Go Driver |
| Component/s: | BSON |
| Affects Version/s: | None |
| Fix Version/s: | 1.3.0 |
| Type: | New Feature | Priority: | Major - P3 |
| Reporter: | zzn | Assignee: | Divjot Arora (Inactive) |
| Resolution: | Fixed | Votes: | 4 |
| Labels: | mgocompat | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Issue Links: |
|
||||
| Epic Link: | MGO BSON compatibility | ||||
| Case: | (copied to CRM) | ||||
| Backwards Compatibility: | Fully Compatible | ||||
| Description |
|
purpose: fix `can not decode null into a xxx type` issues. current possible solution:
solution 1 is very difficult to do if considering team cooperation. solution 3 is too heavy for such small requirement. solution 2 is most acceptable so far, but it will make code ugly, because the compromise between field type and decoder i propose a new tag property: `skipnull`: skip null value(don't touch this field, or set to zero value?) when unmarshaling
this propose assume that in many cases, null value and non-exist is the same thing in mongodb. feel free to close this issue if the assumption don't make much sense
EDIT: We've gotten multiple requests to allow BSON null values to decode into Go types that can't necessarily be nil (e.g. string). We should change our default decoders to accept BSON null values so there's no user configuration required to enable this feature. I'm adding this to the mgo BSON registry epic to help us track the ticket, but it will be enabled as a default for all codecs, not just in the mgo registry. |
| Comments |
| Comment by Githook User [ 30/Jan/20 ] |
|
Author: {'name': 'Divjot Arora', 'username': 'divjotarora', 'email': 'divjot.arora@10gen.com'}Message: |
| Comment by Yao Wei [ 26/Aug/19 ] |
|
Few other suggestions to achieve similar results: 1. Define an Niler interface (like Zeroer but for unmarshaling). 2. (mgo) Define an error SetZero to let decoder set to zero or nil pointer when the error is returned. Currently other than having custom decoder I cannot set nil pointer when unmarshaling. I am looking forward to this change as well. |