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

Allow marshaling custom interfaces inside arrays or structs

    • Type: Icon: Improvement Improvement
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • Labels:
      None

      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:

      Unable to find source-code formatter for language: example.go. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
      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.

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

              Created:
              Updated:
              Resolved: