8000 Correct way to get tag name in xml_field_serializer · Issue #248 · dapper91/pydantic-xml · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Correct way to get tag name in xml_field_serializer #248
Open
@eltoder

Description

@eltoder

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0