title: How to tell Golang Gob encoding that it’s ok to serialize a struct that contains a struct with no exported fields
body: <p>I believe this is a legitimate use case for Gob serialization. Yet <code>enc.Encode</code> returns an error because <code>Something</code> has no exported field. Note that I’m not serializing <code>Something</code> directly but only <code>Composed</code> that contains exported fields.</p>
  
  <p>The only workaround I’ve found was to add a <code>Dummy</code> (exported) value to <code>Something</code>. This is ugly. Is there a more elegant solution?</p>
  
  <p><a href="https://play.golang.org/p/0pL6BfBb78m" rel="nofollow noreferrer">https://play.golang.org/p/0pL6BfBb78m</a></p>
  
  <pre><code>package main
  
  import (
      "bytes"
      "encoding/gob"
  )
  
  type Something struct {
      temp int
  }
  
  func (*Something) DoSomething() {}
  
  type Composed struct {
      Something
      DataToSerialize int
  }
  
  func main() {
      enc := gob.NewEncoder(&amp;bytes.Buffer{})
      err := enc.Encode(Composed{})
      if err != nil {
          panic(err)
      }
  }
  </code></pre>