Uploaded image for project: 'Go Driver'
  1. Go Driver
  2. GODRIVER-1525

Extended JSON parser doesn't handle nested struct

    XMLWordPrintableJSON

Details

    • Icon: Bug Bug
    • Resolution: Cannot Reproduce
    • Icon: Major - P3 Major - P3
    • None
    • None
    • JSON & ExtJSON
    • None

    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.

      Attachments

        Activity

          People

            Unassigned Unassigned
            david.golub@mongodb.com David Golub
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: