title: gorm unsupported data type interface
body: <p>gorm unsupported data type interface.</p>
  <p>How do I save different structures to one field in json (gorm)? Type checking needed, not just serialization in Json.</p>
  <p>Example code with error: unsupported data type: models.Fields</p>
  <pre><code>// table questions (GORM)
  type Questions struct {
      ID
      Fields  `json:&quot;fields&quot;`
  //  .....
  }
  
  type Fields interface{
  //  ...
  }
  
  // radio ----------
  type Radio struct {
      Text string
      Img string
      //  ...
  }
  
  func (d Radio) Value() (driver.Value, error) {
      return json.Marshal(d)
  }
  
  func (d *Radio) Scan(value interface{}) error {
      b, ok := value.([]byte)
      if !ok {
          return errors.New(&quot;type assertion to []byte failed&quot;)
      }
      return json.Unmarshal(b, &amp;d)
  }
  
  // Checkbox ----------
  type Checkbox struct {
      Text string
      MaxCheckbox   uint16
      //  ...
  }
  
  func (d Checkbox) Value() (driver.Value, error) {
      return json.Marshal(d)
  }
  
  func (d *Checkbox) Scan(value interface{}) error {
      b, ok := value.([]byte)
      if !ok {
          return errors.New(&quot;type assertion to []byte failed&quot;)
      }
      return json.Unmarshal(b, &amp;d)
  }
  </code></pre>