MustJSONUnmarshaler requires parameter value to exist to bind to destination implementing json.Unmarshaler interface. Returns error when value does not exist
(sourceParam string, dest json.Unmarshaler)
| 365 | // MustJSONUnmarshaler requires parameter value to exist to bind to destination implementing json.Unmarshaler interface. |
| 366 | // Returns error when value does not exist |
| 367 | func (b *ValueBinder) MustJSONUnmarshaler(sourceParam string, dest json.Unmarshaler) *ValueBinder { |
| 368 | if b.failFast && b.errors != nil { |
| 369 | return b |
| 370 | } |
| 371 | |
| 372 | tmp := b.ValueFunc(sourceParam) |
| 373 | if tmp == "" { |
| 374 | b.setError(b.ErrorFunc(sourceParam, []string{tmp}, "required field value is empty", nil)) |
| 375 | return b |
| 376 | } |
| 377 | |
| 378 | if err := dest.UnmarshalJSON([]byte(tmp)); err != nil { |
| 379 | b.setError(b.ErrorFunc(sourceParam, []string{tmp}, "failed to bind field value to json.Unmarshaler interface", err)) |
| 380 | } |
| 381 | return b |
| 382 | } |
| 383 | |
| 384 | // TextUnmarshaler binds parameter to destination implementing encoding.TextUnmarshaler interface |
| 385 | func (b *ValueBinder) TextUnmarshaler(sourceParam string, dest encoding.TextUnmarshaler) *ValueBinder { |