MCPcopy
hub / github.com/fastapi/fastapi / _serialize_data

Function _serialize_data

fastapi/routing.py:487–510  ·  view source on GitHub ↗
(data: Any)

Source from the content-addressed store, hash-verified

485 # Validates against stream_item_field when set, then
486 # serializes to JSON bytes.
487 def _serialize_data(data: Any) -> bytes:
488 if stream_item_field:
489 value, errors_ = stream_item_field.validate(
490 data, {}, loc=("response",)
491 )
492 if errors_:
493 ctx = endpoint_ctx or EndpointContext()
494 raise ResponseValidationError(
495 errors=errors_,
496 body=data,
497 endpoint_ctx=ctx,
498 )
499 return stream_item_field.serialize_json(
500 value,
501 include=response_model_include,
502 exclude=response_model_exclude,
503 by_alias=response_model_by_alias,
504 exclude_unset=response_model_exclude_unset,
505 exclude_defaults=response_model_exclude_defaults,
506 exclude_none=response_model_exclude_none,
507 )
508 else:
509 data = jsonable_encoder(data)
510 return json.dumps(data).encode("utf-8")
511
512 if is_sse_stream:
513 # Generator endpoint: stream as Server-Sent Events

Callers 2

_serialize_sse_itemFunction · 0.85
_serialize_itemFunction · 0.85

Calls 6

EndpointContextClass · 0.90
jsonable_encoderFunction · 0.90
serialize_jsonMethod · 0.80
validateMethod · 0.45
dumpsMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…