pydantic-xml
pydantic-xml copied to clipboard
way to create mixed xml\non-xml models
First of all, many thanks for good library. Question is - is there a way to create mixed model like
class MyModel(BaseModel):
a: int
b: str
class XmlModel(BaseXmlModel):
b: MyModel = Field()
a: str = attr()
where XmlModel.b is ignored when deserializing\serializing to xml?
Clarification - to be used with model_dump to dict, but ignored for xml.
@hellozyemlya Hi,
Thanks for your feedback!
You should use PrivateAttr instead of Field:
class MyModel(BaseModel):
a: int
b: str
class XmlModel(BaseXmlModel):
_b: MyModel = PrivateAttr()
a: str = attr()
@dapper91 sorry, my question was clarified - the field must be still accounted in model_dump\model_validate.