[GODRIVER-703] UnmarshalExtJSON cannot decode null into a string type Created: 14/Dec/18  Updated: 27/Oct/23  Resolved: 07/Jan/19

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

Type: Bug Priority: Major - P3
Reporter: exfly Assignee: Unassigned
Resolution: Works as Designed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

go 1.11.1



 Description   

type User struct {
    B string `bson:"b"`
    C string `bson:"c,omitempty"` 
}
 
func Test_UnmarshalB(t *testing.T) {
     payload := `{"c": null, "b": "b"}`
     internal := User{}
     err := bson.UnmarshalExtJSON([]byte(payload), false, &internal)
     t.Errorf("%#v %v", internal, err)
}

>>>   mgdbugs.User{B:"", C:""} cannot decode null into a string type



 Comments   
Comment by Kristofer Brandow (Inactive) [ 07/Jan/19 ]

Hi exfly,

Currently, we do not support encoding string into null so we do not support decoding null into a string. If you want to enable this, you can register a decoder for the string type that can handle turning null into a string.

Thanks,

Kris

Comment by exfly [ 15/Dec/18 ]

sorry the env of mongo-go-driver: v0.1.0

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