Skip to content

Discriminate between element not provided and element provided with empty string #306

@skewty

Description

@skewty

Example 1

<foo><next></next></foo>

Example 2

<foo></foo>

Sample Code

from pydantic_xml import BaseXmlModel, element

class Foo(BaseXmlModel, tag='foo'):
    next: str | None = element("next", default=None)

If next is provided with empty string (example 1) I need it to equal '', if it not provided (example 2) I need it to equal None.

How do I accomplish this?

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