serialization

litestar.serialization.decode_json(value: str | bytes, target_type: type[T] | EmptyType = _EmptyEnum.EMPTY, type_decoders: TypeDecodersSequence | None = None, strict: bool = True) Any[源代码]

Decode a JSON string/bytes into an object.

参数:
  • value -- Value to decode

  • target_type -- An optional type to decode the data into

  • type_decoders -- Optional sequence of type decoders

  • strict -- Whether type coercion rules should be strict. Setting to False enables a wider set of coercion rules from string to non-string types for all values

返回:

An object

抛出:

SerializationException -- If error decoding value.

litestar.serialization.decode_msgpack(value: bytes, target_type: type[T] | EmptyType = _EmptyEnum.EMPTY, type_decoders: TypeDecodersSequence | None = None, strict: bool = True) Any[源代码]

Decode a MessagePack string/bytes into an object.

参数:
  • value -- Value to decode

  • target_type -- An optional type to decode the data into

  • type_decoders -- Optional sequence of type decoders

  • strict -- Whether type coercion rules should be strict. Setting to False enables a wider set of coercion rules from string to non-string types for all values

返回:

An object

抛出:

SerializationException -- If error decoding value.

litestar.serialization.default_deserializer(target_type: Any, value: Any, type_decoders: TypeDecodersSequence | None = None) Any[源代码]

Transform values non-natively supported by msgspec

参数:
  • target_type -- Encountered type

  • value -- Value to coerce

  • type_decoders -- Optional sequence of type decoders

返回:

A msgspec-supported type

litestar.serialization.default_serializer(value: Any, type_encoders: Mapping[Any, Callable[[Any], Any]] | None = None) Any[源代码]

Transform values non-natively supported by msgspec

参数:
  • value -- A value to serialized

  • type_encoders -- Mapping of types to callables to transforming types

返回:

A serialized value

抛出:

TypeError -- if value is not supported

litestar.serialization.encode_json(value: Any, serializer: Callable[[Any], Any] | None = None) bytes[源代码]

Encode a value into JSON.

参数:
  • value -- Value to encode

  • serializer -- Optional callable to support non-natively supported types.

返回:

JSON as bytes

抛出:

SerializationException -- If error encoding obj.

litestar.serialization.encode_msgpack(value: ~typing.Any, serializer: ~typing.Callable[[~typing.Any], ~typing.Any] | None = <function default_serializer>) bytes[源代码]

Encode a value into MessagePack.

参数:
  • value -- Value to encode

  • serializer -- Optional callable to support non-natively supported types

返回:

MessagePack as bytes

抛出:

SerializationException -- If error encoding obj.

litestar.serialization.get_serializer(type_encoders: TypeEncodersMap | None = None) Serializer[源代码]

Get the serializer for the given type encoders.