title: Unmarshalling JSON string into a constant
body: <p>In my Go code I have the following situation:</p>
  
  <pre><code>type Operator int
  const (
      UNKNOWN  Operator = iota
      EQUALS
      CONTAINS
      BETWEEN
      DISTANCE
  )
  
  type Filter struct {
      Field string      `json:"field"`
      Operator Operator `json:"operator"`
      Values []string   `json:"values"`
  }
  </code></pre>
  
  <p>My expected JSON would look like the following:</p>
  
  <pre><code>{
      "operator": "EQUALS",
      "field": "name",
      "values": [ "John", "Doe" ]
  }
  </code></pre>
  
  <p>Can I create a mapping such that <a href="http://golang.org/pkg/encoding/json/#Unmarshal" rel="nofollow noreferrer">json.Unmarshal</a> will set the right operator constant in the Filter struct?
  I am aware of the <a href="http://golang.org/pkg/encoding/json/#Unmarshaler" rel="nofollow noreferrer">Unmarshaler</a> interface but I don't think this can really be used on a constant value..</p>
  
  <p>I would really like to keep the constants in my go code since this nicely enforces type checking and consistency when I pass them around.</p>