// UnmarshalJSON implements the encoding/json Unmarshaler interface. It will
// decode a given []byte into b, so long as the provided []byte is
// a valid base64 encoded string or a null.
//
// An empty string will result in a valid-but-empty ByteSlice. The keyword
// 'null' will result in a null ByteSlice. The string '"null"' is considered
// to be a string -- not a keyword -- and will result in base64 decoded garbage.
//
// If the decode fails, the value of b will be unchanged.
UnmarshalJSON implements the encoding/json Unmarshaler interface. It will
decode a given []byte into b, so long as the provided []byte is
a valid base64 encoded string or a null.

An empty string will result in a valid-but-empty ByteSlice. The keyword
'null' will result in a null ByteSlice. The string '"null"' is considered
to be a string -- not a keyword -- and will result in base64 decoded garbage.

If the decode fails, the value of b will be unchanged.
// UnmarshalJSON implements the encoding / json Unmarshaler interface . It will // decode a given [] byte into b so long as the provided [] byte is // a valid base64 encoded string or a null . // // An empty string will result in a valid - but - empty ByteSlice . The keyword // ' null ' will result in a null ByteSlice . The string ' " null " ' is considered // to be a string -- not a keyword -- and will result in base64 decoded garbage . // // If the decode fails the value of b will be unchanged .
func (b *ByteSlice) UnmarshalJSON(data []byte) error {
	if b == nil {
		return fmt.Errorf("null.ByteSlice: UnmarshalJSON called on nil pointer")
	}
	var j interface{}
	if err := json.Unmarshal(data, &j); err != nil {
		return err
	}
	switch val := j.(type) {
	case nil:
		b.ByteSlice = nil
		b.Valid = false
		return nil
	case string:
		if len(val) == 0 {
			b.ByteSlice = []byte{}
			b.Valid = true
			return nil
		}
		var tmp []byte
		err := json.Unmarshal(data, &tmp)
		if err != nil {
			return err
		}
		b.ByteSlice = tmp
		b.Valid = true
		return nil
	default:
		return fmt.Errorf("null.ByteSlice: cannot unmarshal JSON of type %T (%v)",
			val, data)
	}
}
func ( b * ByteSlice ) UnmarshalJSON ( data [ ] byte ) error { if b == nil { return fmt . Errorf ( " " ) } var j interface { } if err := json . Unmarshal ( data , & j ) ; err != nil { return err } switch val := j . ( type ) { case nil : b . ByteSlice = nil b . Valid = false return nil case string : if len ( val ) == 0 { b . ByteSlice = [ ] byte { } b . Valid = true return nil } var tmp [ ] byte err := json . Unmarshal ( data , & tmp ) if err != nil { return err } b . ByteSlice = tmp b . Valid = true return nil default : return fmt . Errorf ( " " , val , data ) } }
UnmarshalJSON implements the encoding/json Unmarshaler interface.
UnmarshalJSON implements the encoding / json Unmarshaler interface .
// We were passed something similar to a string that is an empty // string (`""`). This should result in an empty-but-valid slice. // Call json.Unmarshal again, this time with a []byte as the dest. This // lets encoding/json package take care of the base64 decoding.