def default_dict_serializer(obj: dict, strip_nulls: bool = False, key_transformer: Callable[[str], str] = None, **kwargs) -> dict: """ 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. """ result = dict() for key in obj: dumped_elem = _common_impl.dump(obj[key], key_transformer=key_transformer, strip_nulls=strip_nulls, **kwargs) if not (strip_nulls and dumped_elem is None): if key_transformer: key = key_transformer(key) result[key] = dumped_elem return result
def default_iterable_serializer(obj, **kwargs) -> list: """ 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. """ return [_common_impl.dump(elem, **kwargs) for elem in obj]