title: Unmarshal JSON with "valid" zero values
body: <p>I have some JSON that I am unmarshalling into various structs so that I can then process the data, seemingly this is turning into the hardest part of the project!!!</p>
  
  <p>The format of this JSON is that if the field is missing then it is essentially nil.  This is following on from <a href="https://stackoverflow.com/questions/40970422/default-struct-values">Default struct values</a> but thought it deserved it's own question on SO.  </p>
  
  <p>A zero therefore is a valid value and I need to be able to discern this in my Go code.  Is there a way to get Go to unmarshal into this struct with pointers at all?</p>
  
  <p>In the example <a href="https://play.golang.org/p/B3-sos2FaH" rel="nofollow noreferrer">playground</a> you can see what I mean, it "appears" to work but when I come to print out one of the pointer values it always prints the pointer address and not the actual value.</p>
  
  <pre><code>package main
  
  import "fmt"
  import "log"
  import "encoding/json"
  
  const inputMissing = `
  ["AAAAAA", {"testCode" : "Sss"}, 123456]
  `
  
  const inputZero = `
  ["AAAAAA", {"testCode" : "Sss", "missingInt" : 0, "defaultInt" : 0,"missingString" : "", "defaultString" : ""}, 123456]
  `
  
  type RawMessage struct {
      AlwaysString  string
      ClientData    ClientData
      ReceptionTime int
  }
  
  type ClientData struct {
      TestCode   string
      MissingInt *int
      DefaultInt int
  
      MissingString *string
      DefaultString string
  }
  
  func main() {
  
      var n RawMessage
      if err := json.Unmarshal([]byte(inputMissing), &amp;n); err != nil {
          log.Fatal(err)
      }
  
      fmt.Printf("%#v\n", n)
  
      var o RawMessage
      if err := json.Unmarshal([]byte(inputZero), &amp;o); err != nil {
          log.Fatal(err)
      }
  
      fmt.Printf("%#v\n", o)
  
      fmt.Printf("Should print the value of the int, not pointer... %i", o.ClientData.MissingInt)
  }
  
  func (n *RawMessage) UnmarshalJSON(buf []byte) error {
      tmp := []interface{}{&amp;n.AlwaysString, &amp;n.ClientData, &amp;n.ReceptionTime}
      wantLen := len(tmp)
      if err := json.Unmarshal(buf, &amp;tmp); err != nil {
          return err
      }
      if g, e := len(tmp), wantLen; g != e {
          return fmt.Errorf("wrong number of fields in RawMessage: %d != %d", g, e)
      }
      return nil
  }
  </code></pre>