Open
Description
In the code below I'm writing a custom serializer for list[int]
fields. In the serializer I need to know the tag name of the field, rather than the field name. These are not the same because tag names contain dashes (-
), so I had to rename them:
import pydantic_xml as pxml
class Model(pxml.BaseXmlModel):
x_ids: list[int] = pxml.element(tag="x-ids")
y_ids: list[int] = pxml.element(tag="y-ids")
@pxml.xml_field_serializer("x_ids", "y_ids")
def _serialize_ids(self, elem, value, field):
# need the tag name ("x-ids" or "y-ids") here
What is the recommended way to get the tag name?