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

fix pointers' decoding

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 0.0.6
    • Affects Version/s: 0.0.5
    • Component/s: BSON
    • Labels:
      None

      Came across a problem with decoding pointers.
      Example of code to reproduce common issue:

      package main
      
      import (
      	"github.com/mongodb/mongo-go-driver/bson"
      	"log"
      )
      
      type TestStruct struct {
      	TestValue *string `bson:"test_value,omitempty"`
      }
      
      func main() {
      	testString := "test value goes here"
      	t := TestStruct{
      		TestValue: &testString,
      	}
      	data, err := bson.Marshal(t)
      	if err != nil {
      		log.Fatalf("Failed to marshal. Error: %v", err)
      	}
      	unt := TestStruct{}
      	err = bson.Unmarshal(data, &unt)
      	if err != nil {
      		log.Fatalf("Failed to unmarshal. Error: %v", err)
      	}
      	log.Printf("Result: %+v")
      	if unt.TestValue == nil {
      		return
      	}
      	log.Printf("Contained string: %+v", *unt.TestValue)
      }
      

      Code like the one above gives error like:

      reflect.Value.Addr of unaddressable value
      

            Assignee:
            Unassigned Unassigned
            Reporter:
            kris.brandow@mongodb.com Kristofer Brandow (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: