-
Type: New Feature
-
Resolution: Fixed
-
Priority: Major - P3
-
Affects Version/s: None
-
Component/s: BSON
-
(copied to CRM)
-
Fully Compatible
purpose: fix `can not decode null into a xxx type` issues.
current possible solution:
- change data in mongodb
- use pointer type, e.g. define field as type `*string` but not `string`
- customize the bson decoder
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.