MCPcopy
hub / github.com/ory/hydra / decodeJSON

Function decodeJSON

oryx/decoderx/http.go:537–561  ·  view source on GitHub ↗
(r *http.Request, destination interface{}, o *httpDecoderOptions)

Source from the content-addressed store, hash-verified

535}
536
537func decodeJSON(r *http.Request, destination interface{}, o *httpDecoderOptions) error {
538 reader, err := requestBody(r, o)
539 if err != nil {
540 return err
541 }
542
543 raw, err := io.ReadAll(reader)
544 if err != nil {
545 return errors.WithStack(herodot.ErrBadRequest.WithReasonf("Unable to read HTTP POST body: %s", err))
546 }
547
548 dc := json.NewDecoder(bytes.NewReader(raw))
549 if err := dc.Decode(destination); err != nil {
550 return errors.WithStack(herodot.ErrBadRequest.WithReasonf("Unable to decode JSON payload: %s", err).WithDebugf("Received request body: %s", string(raw)))
551 }
552
553 if err := validatePayload(r.Context(), raw, o); err != nil {
554 if o.expectJSONFlattened && strings.Contains(err.Error(), "json: unknown field") {
555 return decodeJSONForm(r, destination, o)
556 }
557 return err
558 }
559
560 return nil
561}

Callers 1

DecodeFunction · 0.85

Calls 6

requestBodyFunction · 0.85
validatePayloadFunction · 0.85
decodeJSONFormFunction · 0.85
WithDebugfMethod · 0.80
DecodeMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected