SlyMastodon.serialization#
Extended support for deserialization of Python types from JSON
Functions
|
Convert a json value to a T instance. |
Classes
Mixin for dataclasses to add a from_json method |
- SlyMastodon.serialization.convert_from_json(cls: type[T], value: int | float | bool | str | None | Sequence[JsonTypeCo] | Mapping[str, JsonTypeCo], typevars_: dict[str, type] | None = None, parent: type | None = None) T #
Convert a json value to a T instance.
May not round-trip, especially if a member of T is a union of multiple types with the same representation (e.g. set | list, dict | dataclass)
Fails if representation was different than what was expected. Additional supported types different from json:
datetime.datetime
enum.Enum
set[T], tuple[T, …]
dataclasses (assuming all members are convertable)
TypeAliases
Generic TypeAliases and dataclasses