xsdata.formats.dataclass.serializers package¶
Subpackages¶
Submodules¶
Module contents¶
-
class
xsdata.formats.dataclass.serializers.
JsonSerializer
(indent=None, encoder=<class 'xsdata.formats.dataclass.serializers.json.JsonEncoder'>, dict_factory=<class 'dict'>)[source]¶ Bases:
xsdata.formats.bindings.AbstractSerializer
Simple json.dumps wrapper.
- Parameters
-
encoder
¶ alias of
JsonEncoder
-
dict_factory
¶ alias of
builtins.dict
-
class
xsdata.formats.dataclass.serializers.
DictFactory
[source]¶ Bases:
object
Dictionary factory types.
-
class
xsdata.formats.dataclass.serializers.
XmlSerializer
(encoding='UTF-8', pretty_print=False, context=<factory>, writer=<class 'xsdata.formats.dataclass.serializers.writers.lxml.LxmlEventWriter'>)[source]¶ Bases:
xsdata.formats.bindings.AbstractSerializer
Xml serialize for dataclasses.
- Parameters
encoding (
str
) – Text encodingpretty_print (
bool
) – Enable pretty outputcontext (
XmlContext
) – XmlContext instance
-
render
(obj, ns_map=None)[source]¶ Convert and return the given object tree as xml string.
Optionally provide a prefix-URI namespaces mapping.
-
write
(out, obj, ns_map=None)[source]¶ Write the given object tree to output text stream.
Optionally provide a prefix-URI namespaces mapping.
-
write_object
(obj)[source]¶ Produce an events stream from a dataclass or a derived element.
- Parameters
obj (
Any
) –
-
write_dataclass
(obj, namespace=None, qname=None, nillable=False, xsi_type=None)[source]¶ Produce an events stream from a dataclass.
Optionally override the qualified name and the xsi properties type and nil.
-
write_xsi_type
(value, var, namespace)[source]¶ Produce an events stream from a dataclass for the given var with with xsi abstract type check for non wildcards.
-
write_value
(value, var, namespace)[source]¶ Delegates the given value to the correct writer according to the variable metadata.
The order of the checks is important as more than one condition can be true.
-
write_tokens
(value, var, namespace)[source]¶ Produce an events stream for the given tokens list or list of tokens lists.
-
write_mixed_content
(values, var, namespace)[source]¶ Produce an events stream for the given list of mixed type objects.
-
write_any_type
(value, var, namespace)[source]¶ Produce an events stream for the given object.
The object can be a dataclass or a generic object or any other simple type.
-
write_wildcard
(value, var, namespace)[source]¶ Produce an element events stream for the given generic object.
- Parameters
value (
AnyElement
) –var (
XmlVar
) –
- Return type
-
write_elements
(value, var, namespace)[source]¶ Produce an events stream from compound elements field.
-
write_choice
(value, var, namespace)[source]¶ Produce an events stream for the given value of a compound elements field.
The value can be anything as long as we can match the qualified name or its type to a choice.
-
classmethod
write_element
(value, var, namespace)[source]¶ Produce an element events stream for the given simple type value.
-
classmethod
next_value
(obj, meta)[source]¶ Return the non attribute variables with their object values in the correct order according to their definition and the sequential metadata property.
Sequential fields need to be rendered together in parallel order eg: <a1/><a2/><a1/><a/2></a1>