title: Golang struct having io.Reader unable to serialize
body: <p>I am trying to serialize below struct into <code>byte[]</code> to store it into DB and then while reading it from DB I am deserializing it.</p>
  
  <pre><code>type Response struct {
      Headers map[string][]string
      Body    io.Reader
      Status  int
  }
  </code></pre>
  
  <p>Below is the code how I am creating response object and setting up the value for it.</p>
  
  <pre><code>resp := new(Response)
  resp.Body = bytes.NewReader(outBytes) //outBytes is byte[]
  resp.Headers.SetKeyValue("Content-Type", "text/json") //SetKeyValue is the method created for adding headers
  resp.Headers.SetKeyValue("Url-Type", "broker")
  resp.Status = 200
  </code></pre>
  
  <p>I am using <code>json.Marshal()</code> to serialize the <code>resp</code> object as below.</p>
  
  <pre><code>b, _ := json.Marshal(resp)
  </code></pre>
  
  <p>Below is the code, I am using to deserialize.</p>
  
  <pre><code>var r Response
  r.Body = &amp;bytes.Buffer{}
  json.Unmarshal(b,&amp;r)
  </code></pre>
  
  <p>Problem is with deserialization, I am not able to get the <code>resp.Body</code> object. It is always <code>nil</code> or blank in spite of setting body object (see above). I am able to get <code>Headers</code> and <code>Status</code> field of the struct back from deserialize but not <code>Body</code>.</p>
  
  <p>I know there is something to be handle with <code>Body</code> field which is an <code>io.Reader</code>. </p>
  
  <p>Any help would be really great.</p>