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

Allow marshaling custom interfaces inside arrays or structs

    XMLWordPrintableJSON

Details

    • Icon: Improvement Improvement
    • Resolution: Done
    • Icon: Major - P3 Major - P3
    • None
    • None
    • None
    • None

    Description

      This can be considered a follow-up of GODRIVER-842, that the custom interfaces inside arrays or structs cannot be marshaled.

      Example is shown as follows:

      type I interface {}
       
      type A struct {
      	X string
      }
       
      type B struct {
      	Y I
      }
       
      func (*A) Hello() {}
       
      func main() {
      	a := A{X: "meow"}
      	b := B{Y: &a}
      	_, err := bson.Marshal(b)
      	fmt.Println(err)
      }
      

      It returns "no encoder found for main.I" in current state. However, bson.Marshal can actaully work with interface{} inside struct, as well as custom interfaces if it is not inside a struct, so I would expect interface{} inside struct should work.

      Attachments

        Activity

          People

            manny.eppinger@mongodb.com Emmanuel Eppinger (Inactive)
            mwei Yao Wei
            Votes:
            1 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: