django_unicorn.serializer
#
Module Contents#
- django_unicorn.serializer.PydanticBaseModel#
- django_unicorn.serializer.django_json_encoder#
- exception django_unicorn.serializer.JSONDecodeError#
Bases:
Exception
Common base class for all non-exit exceptions.
- exception django_unicorn.serializer.InvalidFieldNameError(field_name: str, data: Optional[Dict] = None)#
Bases:
Exception
Common base class for all non-exit exceptions.
- exception django_unicorn.serializer.InvalidFieldAttributeError(field_name: str, field_attr: str, data: Optional[Dict] = None)#
Bases:
Exception
Common base class for all non-exit exceptions.
- django_unicorn.serializer.dumps(data: Dict, *, fix_floats: bool = True, exclude_field_attributes: Optional[Tuple[str, Ellipsis]] = None, sort_dict: bool = True) str #
Converts the passed-in dictionary to a string representation.
Handles the following objects: dataclass, datetime, enum, float, int, numpy, str, uuid, Django Model, Django QuerySet, Pydantic models (PydanticBaseModel), any object with to_json method.
- Parameters:
fix_floats (param) – Whether any floats should be converted to strings. Defaults to True, but will be faster without it.
exclude_field_attributes (param) – Tuple of strings with field attributes to remove, i.e. “1.2” to remove the key 2 from {“1”: {“2”: “3”}}
sort_dict (param) – Whether the dict should be sorted. Defaults to True, but will be faster without it.
Returns a str instead of bytes (which deviates from orjson.dumps), but seems more useful.