// UnmarshalJSON implements the encoding/json Unmarshaler interface. It will
// decode a given []byte into i, so long as the provided []byte is a valid JSON
// representation of an int. The 'null' keyword will decode into a null Uint8.
//
// If the decode fails, the value of i will be unchanged.
UnmarshalJSON implements the encoding/json Unmarshaler interface. It will
decode a given []byte into i, so long as the provided []byte is a valid JSON
representation of an int. The 'null' keyword will decode into a null Uint8.

If the decode fails, the value of i will be unchanged.
// UnmarshalJSON implements the encoding / json Unmarshaler interface . It will // decode a given [] byte into i so long as the provided [] byte is a valid JSON // representation of an int . The ' null ' keyword will decode into a null Uint8 . // // If the decode fails the value of i will be unchanged .
func (i *Uint8) UnmarshalJSON(data []byte) error {
	if i == nil {
		return fmt.Errorf("null.Uint8: UnmarshalJSON called on nil pointer")
	}
	var j interface{}
	if err := json.Unmarshal(data, &j); err != nil {
		return err
	}
	switch val := j.(type) {
	case float64:
		var tmp uint8
		err := json.Unmarshal(data, &tmp)
		if err != nil {
			return err
		}
		i.Uint8 = tmp
		i.Valid = true
		return nil
	case nil:
		i.Uint8 = 0
		i.Valid = false
		return nil
	default:
		return fmt.Errorf("null.Uint8: cannot unmarshal JSON of type %T (%v)",
			val, data)
	}
}
func ( i * Uint8 ) UnmarshalJSON ( data [ ] byte ) error { if i == nil { return fmt . Errorf ( " " ) } var j interface { } if err := json . Unmarshal ( data , & j ) ; err != nil { return err } switch val := j . ( type ) { case float64 : var tmp uint8 err := json . Unmarshal ( data , & tmp ) if err != nil { return err } i . Uint8 = tmp i . Valid = true return nil case nil : i . Uint8 = 0 i . Valid = false return nil default : return fmt . Errorf ( " " , val , data ) } }
UnmarshalJSON implements the encoding/json Unmarshaler interface.
UnmarshalJSON implements the encoding / json Unmarshaler interface .
// Perform a second unmarshal, this time into a uint8. This give the // JSON parse a chance to meaningfully fail (eg. if the conversion from // float to integer will result in a loss of precision).