serializers

This module contains default serializers. You can override the serialization process of a particular type as follows:

jsons.set_serializer(custom_deserializer, SomeClass)

Module Contents

Functions

default_iterable_serializer(obj,**kwargs) Serialize the given obj to a list of serialized objects.
default_list_serializer(obj,**kwargs) Serialize the given obj to a list of serialized objects.
default_tuple_serializer(obj,**kwargs) Serialize the given obj to a list of serialized objects.
default_dict_serializer(obj,strip_nulls=False,key_transformer=None,**kwargs) Serialize the given obj to a dict of serialized objects.
default_enum_serializer(obj,use_enum_name=True,**_) Serialize the given obj. By default, the name of the enum element is
default_datetime_serializer(obj,**_) Serialize the given datetime instance to a string. It uses the RFC3339
default_primitive_serializer(obj,**_) Serialize a primitive; simply return the given obj.
default_object_serializer(obj,key_transformer=None,strip_nulls=False,**kwargs) Serialize the given obj to a dict. All values within obj are also
default_iterable_serializer(obj, **kwargs)

Serialize the given obj to a list of serialized objects. :param obj: the iterable that is to be serialized. :param kwargs: any keyword arguments that may be given to the serialization process. :return: a list of which all elements are serialized.

default_list_serializer(obj, **kwargs)

Serialize the given obj to a list of serialized objects. :param obj: the list that is to be serialized. :param kwargs: any keyword arguments that may be given to the serialization process. :return: a list of which all elements are serialized.

default_tuple_serializer(obj, **kwargs)

Serialize the given obj to a list of serialized objects. :param obj: the tuple that is to be serialized. :param kwargs: any keyword arguments that may be given to the serialization process. :return: a list of which all elements are serialized.

default_dict_serializer(obj, strip_nulls=False, key_transformer=None, **kwargs)

Serialize the given obj to a dict of serialized objects. :param obj: the dict that is to be serialized. :param key_transformer: a function that will be applied to all keys in the resulting dict. :param strip_nulls: if True the resulting dict will not contain null values. :param kwargs: any keyword arguments that may be given to the serialization process. :return: a dict of which all elements are serialized.

default_enum_serializer(obj, use_enum_name=True, **_)

Serialize the given obj. By default, the name of the enum element is returned. :param obj: an instance of an enum. :param use_enum_name: determines whether the name or the value should be used for serialization. :param _: not used. :return: obj serialized as a string.

default_datetime_serializer(obj, **_)

Serialize the given datetime instance to a string. It uses the RFC3339 pattern. If datetime is a localtime, an offset is provided. If datetime is in UTC, the result is suffixed with a ‘Z’. :param obj: the datetime instance that is to be serialized. :param _: not used. :return: datetime as an RFC3339 string.

default_primitive_serializer(obj, **_)

Serialize a primitive; simply return the given obj. :param obj: :param _: not used. :return: obj.

default_object_serializer(obj, key_transformer=None, strip_nulls=False, **kwargs)

Serialize the given obj to a dict. All values within obj are also serialized. If key_transformer is given, it will be used to transform the casing (e.g. snake_case) to a different format (e.g. camelCase). :param obj: the object that is to be serialized. :param key_transformer: a function that will be applied to all keys in the resulting dict. :param strip_nulls: if True the resulting dict will not contain null values. :param kwargs: any keyword arguments that are to be passed to the serializer functions. :return: a Python dict holding the values of obj.