xsdata.formats.dataclass.serializers module¶
-
class
xsdata.formats.dataclass.serializers.
EnumEncoder
(*, 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 aTypeError
).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.
DictSerializer
(dict_factory=<class 'dict'>)[source]¶ Bases:
xsdata.formats.mixins.AbstractSerializer
-
dict_factory
¶ alias of
builtins.dict
-
-
class
xsdata.formats.dataclass.serializers.
JsonSerializer
(dict_factory=<class 'dict'>, encoder=<class 'xsdata.formats.dataclass.serializers.EnumEncoder'>, indent=None)[source]¶ Bases:
xsdata.formats.mixins.AbstractSerializer
- Parameters
-
dict_factory
¶ alias of
builtins.dict
-
encoder
¶ alias of
EnumEncoder
-
indent
: Optional[int] = None¶
-
class
xsdata.formats.dataclass.serializers.
XmlSerializer
(xml_declaration=True, encoding='UTF-8', pretty_print=False)[source]¶ Bases:
xsdata.formats.mixins.AbstractSerializer
,xsdata.formats.dataclass.mixins.ModelInspect
- Parameters
-
xml_declaration
: bool = True¶
-
encoding
: str = 'UTF-8'¶
-
pretty_print
: bool = False¶
-
ns_list
: list = None¶
-
render_tree
(obj)[source]¶ Convert a dataclass instance to a nested Element structure.
If the instance class is generated from the xsdata cli the root element’s name will be auto assigned otherwise it will default to the class name.
- Raises
TypeError – If the instance is not a dataclass
- Return type
Element