title: Defining custom unmarshalling for non-built in types
body: <p>Most of us know that a JSON object can be unmarshaled with JSON tags:</p>
  
  <pre><code>var jsonData = `{"name": "Brown Bear"}`
  
  type Elephant struct {
      Name string `json:"name"`
  }
  </code></pre>
  
  <p>This is because <code>string</code> is a built in types. But what if <code>Name</code> were not a built in type, and we wanted to use this type across different structs?</p>
  
  <pre><code>var jsonData = `{"name": "Brown Bear"}`
  
  type Elephant struct {
      Name Name   `json:"name"`  // Unmarshalling fails here
  }
  
  type Feline struct {
      Name Name   `json:"name"`  // Unmarshalling fails here
  }
  
  type Bear struct {
      Name Name   `json:"name"`  // Unmarshalling fails here
  }
  
  type Name struct {
      CommonName     string
      ScientificName string  // This field should intentionally be blank
  }
  </code></pre>
  
  <p>Is there a way we can define the <code>Name</code> type so that the <code>json</code> unmarshaller knows how to unmarshal it?</p>
  
  <p>PS: The solution I want to avoid is creating <code>UnmarshalJSON</code> methods for <code>Elephant</code>, <code>Feline</code>, and <code>Bear</code> above. It would be better to create a method just for the <code>Name</code> type.</p>