Data Bindings#

All the xsdata XML and JSON bindings are available. There is an extra requirement to specify the class type of the data models to the XmlContext that among other stuff also acts as a compatibility layer between dataclasses and pydantic dataclasses


The plugin is using xsdata’s data bindings to parse json/xml, only xsdata’s types are supported!

Specify ClassType#

>>> from xsdata.formats.dataclass.parsers import XmlParser
>>> from xsdata.formats.dataclass.parsers import JsonParser
>>> from xsdata.formats.dataclass.serializers import XmlSerializer
>>> from xsdata.formats.dataclass.serializers import JsonSerializer
>>> from xsdata.formats.dataclass.context import XmlContext
>>> context = XmlContext(class_type="pydantic")  # Specify class type pydantic
>>> xml_parser = XmlParser(context=context)
>>> xml_serializer = XmlSerializer(context=context)
>>> json_parser = JsonParser(context=context)
>>> json_serializer = JsonSerializer(context=context)

Binding Shortcuts#

For convenience this plugin comes with subclasses for all the xsdata binding modules with the pydantic context auto initialized.

>>> from xsdata_pydantic.bindings import XmlContext
>>> from xsdata_pydantic.bindings import XmlParser
>>> from xsdata_pydantic.bindings import XmlSerializer
>>> from xsdata_pydantic.bindings import JsonParser
>>> from xsdata_pydantic.bindings import JsonSerializer
>>> from xsdata_pydantic.bindings import UserXmlParser