validatedTypeDecoder wraps the type decoder with a validator. This is helpful for ensuring that enum fields are correct.
(t reflect.Type, entry *validationEntry)
| 144 | // validatedTypeDecoder wraps the type decoder with a validator. This is helpful |
| 145 | // for ensuring that enum fields are correct. |
| 146 | func (d *decoderBuilder) validatedTypeDecoder(t reflect.Type, entry *validationEntry) decoderFunc { |
| 147 | dec := d.typeDecoder(t) |
| 148 | if entry == nil { |
| 149 | return dec |
| 150 | } |
| 151 | |
| 152 | // Thread the current validation entry through the decoder, |
| 153 | // but clean up in time for the next field. |
| 154 | return func(node gjson.Result, v reflect.Value, state *decoderState) error { |
| 155 | state.validator = entry |
| 156 | err := dec(node, v, state) |
| 157 | state.validator = nil |
| 158 | return err |
| 159 | } |
| 160 | } |
| 161 | |
| 162 | func indirectUnmarshalerDecoder(n gjson.Result, v reflect.Value, state *decoderState) error { |
| 163 | return v.Addr().Interface().(json.Unmarshaler).UnmarshalJSON([]byte(n.Raw)) |
no test coverage detected