xsdata.formats.dataclass.serializers module¶
-
class
xsdata.formats.dataclass.serializers.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 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.JsonEncoder'>, indent=None)[source]¶ Bases:
xsdata.formats.mixins.AbstractSerializer- Variables
dict_factory – Callable to generate dictionary
encoder – Value encoder
indent – Pretty print indent
-
dict_factory¶ alias of
builtins.dict
-
encoder¶ alias of
JsonEncoder
-
indent: Optional[int] = None¶
-
class
xsdata.formats.dataclass.serializers.XmlSerializer(name_generator=<function ModelInspect.<lambda>>, cache=<factory>, xml_declaration=True, encoding='UTF-8', pretty_print=False)[source]¶ Bases:
xsdata.formats.mixins.AbstractSerializer,xsdata.formats.dataclass.mixins.ModelInspect- Variables
xml_declaration – Add xml declaration
encoding – Result text encoding
pretty_print – Enable pretty output
-
xml_declaration: bool = True¶
-
encoding: str = 'UTF-8'¶
-
pretty_print: bool = False¶
-
render_tree(obj, namespace=None)[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