You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
That is, the metadata consists of a dynamic number of elements with dynamic tags and no attributes, each of which contains just text.
Ideally, I would want this to map to the Python model
class Article:
title: str
metadata: Dict[str, str]
is there a way to achieve that with pydantic-xml? The closest I got so far was by making metadata a raw field, but then working from the Python side gets a little annoying: how do I construct an instance of Article when metadata is ET.Element? I could create a new constructor class method but then I'd have to remember that for this specific model only, I shouldn't use the constructor.
The other approach I expected to work was setting metadata=Field(exclude=True) and implementing a @computed_element for serialization, and a @field_validator for deserialization. Unfortunately the @field_validator approach doesn't work:
Activity
dapper91 commentedon Jun 29, 2024
@zygi Hi,
Right now there is not way to model an element with dynamic tags. The workaround I see is the following:
output: