bson handling of type declaration should be more clear

XMLWordPrintableJSON

    • Type: Task
    • Resolution: Works as Designed
    • Priority: Major - P3
    • None
    • Affects Version/s: None
    • Component/s: BSON
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      I wrote the following test which reflects a problem that we ran into during our migration from mgobson. It was easy to amend our code to avoid this situation, but the error message that you get from Unmarshal in this situation is "cannot decode binary into a slice", which isn't super intuitive, particularly without context, and because the "First" field is what a developer would think of as a slice.

      func TestBinarySlice(t *testing.T) {
      	type raw []byte
      	type fob struct {
      		First raw `bson:"first"`
      	}
      
      	inter := M{
      		"first": []byte("foo"),
      	}
      
      	data, err := Marshal(inter)
      	require.NoError(t, err)
      
      	out := fob{}
      
      	err = Unmarshal(data, &out)
      	require.NoError(t, err)
      
      	require.Equal(t, string(out.First), "foo")
      }
      

            Assignee:
            Divjot Arora (Inactive)
            Reporter:
            Sam Kleinman (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: