xsdata.formats.dataclass.serializers.json module

xsdata.formats.dataclass.serializers.json.filter_none(x)[source]
class xsdata.formats.dataclass.serializers.json.DictFactory[source]

Bases: object

FILTER_NONE()
class xsdata.formats.dataclass.serializers.json.JsonEncoder(*, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, default=None)[source]

Bases: json.encoder.JSONEncoder

default(obj)[source]

Implement this method in a subclass such that it returns a serializable object for o, or calls the base implementation (to raise a TypeError).

For example, to support arbitrary iterators, you could implement default like this:

def default(self, o):
    try:
        iterable = iter(o)
    except TypeError:
        pass
    else:
        return list(iterable)
    # Let the base class default method raise the TypeError
    return JSONEncoder.default(self, o)
class xsdata.formats.dataclass.serializers.json.DictSerializer(dict_factory=<class 'dict'>)[source]

Bases: xsdata.formats.bindings.AbstractSerializer

dict_factory

alias of builtins.dict

render(obj)[source]

Convert the given object tree to dictionary with primitive values.

Return type

Dict

class xsdata.formats.dataclass.serializers.json.JsonSerializer(dict_factory=<class 'dict'>, encoder=<class 'xsdata.formats.dataclass.serializers.json.JsonEncoder'>, indent=None)[source]

Bases: xsdata.formats.bindings.AbstractSerializer

Variables
dict_factory

alias of builtins.dict

encoder

alias of JsonEncoder

indent: Optional[int] = None
render(obj)[source]

Convert the given object tree to json string.

Return type

str