[GODRIVER-1525] Extended JSON parser doesn't handle nested struct Created: 09/Mar/20  Updated: 09/Mar/20  Resolved: 09/Mar/20

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

Type: Bug Priority: Major - P3
Reporter: David Golub Assignee: Unassigned
Resolution: Cannot Reproduce Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

If you attempt to use the extended JSON parser to deserialize a nested struct, it leaves the fields uninitialized. The following snippet will reproduce the behavior:

package main
 
import (
	"fmt"
 
	"go.mongodb.org/mongo-driver/bson"
)
 
type Inner struct {
	Y string `json:"y"`
}
 
type Outer struct {
	X Inner `json:"x"`
}
 
func main() {
	data := []byte(`{x:":{"y":"foo"}}`)
	val := &Outer{}
	bson.UnmarshalExtJSON(data, false, val)
	fmt.Println(val.X.Y)
}

The expected behavior is that it will print foo, but it actually prints an empty string.



 Comments   
Comment by David Golub [ 09/Mar/20 ]

Getting different behavior now than I got back over the weekend. Closing for now and will reopen if I experience this issue again.

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