Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support of dict types #1072

Open
vvmruder opened this issue Sep 4, 2024 · 0 comments
Open

Support of dict types #1072

vvmruder opened this issue Sep 4, 2024 · 0 comments

Comments

@vvmruder
Copy link

vvmruder commented Sep 4, 2024

I encounter a limit Iam curious why it is there.

Assuming the following code:

from dataclasses import dataclass, field
from xsdata.formats.dataclass.parsers import DictDecoder
test_dict = {
    "dict_type": {
        "a": {
            "name": "namea",
            "value": 1
        },
        "b": {
            "name": "nameb",
            "value": 2
        },
        "c": {
            "name": "namec",
            "value": 3
        }
    }
}


@dataclass
class TestMember:
    name: str = field(
        metadata={
            "type": "Element",
            "required": True
        }
    )
    value: int = field(
        metadata={
            "type": "Element",
            "required": True
        }
    )


@dataclass
class Test:
    dict_type: dict[TestMember]


DictDecoder().decode(test_dict, Test)

It will end up with:

xsdata.exceptions.XmlContextError: Error on Test::dict_type: Xml Text does not support typing `dict[__main__.TestMember]`

May I ask, what are the limitations here or for a hint what I did wrong?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant