JSONUnmarshaler binds parameter to destination implementing json.Unmarshaler interface
(sourceParam string, dest json.Unmarshaler)
| 347 | |
| 348 | // JSONUnmarshaler binds parameter to destination implementing json.Unmarshaler interface |
| 349 | func (b *ValueBinder) JSONUnmarshaler(sourceParam string, dest json.Unmarshaler) *ValueBinder { |
| 350 | if b.failFast && b.errors != nil { |
| 351 | return b |
| 352 | } |
| 353 | |
| 354 | tmp := b.ValueFunc(sourceParam) |
| 355 | if tmp == "" { |
| 356 | return b |
| 357 | } |
| 358 | |
| 359 | if err := dest.UnmarshalJSON([]byte(tmp)); err != nil { |
| 360 | b.setError(b.ErrorFunc(sourceParam, []string{tmp}, "failed to bind field value to json.Unmarshaler interface", err)) |
| 361 | } |
| 362 | return b |
| 363 | } |
| 364 | |
| 365 | // MustJSONUnmarshaler requires parameter value to exist to bind to destination implementing json.Unmarshaler interface. |
| 366 | // Returns error when value does not exist |