title: Gob can't encode map with a nil pointer value
body: <p>Gob's Encode returns an error when I try to encode a map to pointers if one of the values is nil. This seems to contradict the docs (but I may be misinterpreting the meaning):</p>
  
  <blockquote>
    <p>In slices and arrays, as well as maps, all elements, even zero-valued elements, are transmitted, even if all the elements are zero.</p>
  </blockquote>
  
  <p>Code:</p>
  
  <pre><code>package main
  
  import (
      "bytes"
      "encoding/gob"
  )
  
  type Dog struct {
      Name string
  }
  
  func main() {
      m0 := make(map[string]*Dog)
      m0["apple"] = nil
  
      // Encode m0 to bytes
      var network bytes.Buffer
      enc := gob.NewEncoder(&amp;network)
      err := enc.Encode(m0)
      if err != nil {
          panic(err) // Output: panic: gob: encodeReflectValue: nil element
      }
  }
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code>panic: gob: encodeReflectValue: nil element
  </code></pre>
  
  <p>Is there a good reason for gob to fail in this case? It seems that either of the two obvious options are preferable to failure: 1) don't encode any keys with values that are zero-valued or 2) encode all keys even if the values are zero-valued. With the current state of things, is the best practice to recursively scan through my struct to see if there are any nil map values, and delete those keys if so? If this check is required, it seems like it should be the responsibility of the encoding/gob package, not the user.</p>
  
  <p>Further, the rule isn't simply "gob can't encode maps where a key has a value of nil" because if the value type is a slice, then nil is accepted:</p>
  
  <pre><code>func main() {
      m0 := make(map[string][]string)
      m0["apple"] = nil
  
      // Encode m0 to bytes
      var network bytes.Buffer
      enc := gob.NewEncoder(&amp;network)
      err := enc.Encode(m0) // err is nil
      if err != nil {
          panic(err) // doesn't panic
      }
  }
  </code></pre>