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

alias broken for list #432

Open
opeik opened this issue Oct 9, 2023 · 3 comments
Open

alias broken for list #432

opeik opened this issue Oct 9, 2023 · 3 comments
Assignees
Labels
bug Bug report or fix

Comments

@opeik
Copy link

opeik commented Oct 9, 2023

Hi there,

Back again with another potential bug. Using [email protected], I've run into deserialization failures for two situations I think should be valid:

@serde
@dataclass
class Foo:
    a: Optional[list[int]] = field(alias=["b"], default=None)

x = from_json(Foo, '{"b": [1]}')
assert x.a == [1] 💥
@serde
@dataclass
class Foo:
    a: list[int] = field(alias=["b"], default_factory=list)

x = from_json(Foo, '{"b": [1]}')
assert x.a == [1] 💥

Both fail with serde.compat.SerdeError: 'a', I wish I could give you a more useful error message.

@yukinarit yukinarit added the bug Bug report or fix label Oct 18, 2023
@yukinarit
Copy link
Owner

Hi @opeik

Sorry, I don't have bandwidth to look into this issue. If you're interested in contributing, I am happy to assist you.

@opeik
Copy link
Author

opeik commented Oct 20, 2023

Hey @yukinarit, don't stress. I would never demand maintainers fix my problems. Thanks for taking a look 🙇‍♀️

@kaiaw
Copy link

kaiaw commented Jan 26, 2024

Just wanted to add to this:

Also doesn't seem to work for nested types

@serde
@dataclass
class Bar:
    e: int
    f: str

@serde
@dataclass
class Foo:
    a: Bar | None = field(default=None, alias=["b"])


# works
s = '{"a": {"e": 5, "f": "baz"}}'
print(f"From Json: {from_json(Foo, s)}")

# works
s = '{"b": null}'
print(f"From Json: {from_json(Foo, s)}")

# doesnt work
s = '{"b": {"e": 5, "f": "baz"}}'
print(f"From Json: {from_json(Foo, s)}")

@yukinarit yukinarit self-assigned this Jun 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Bug report or fix
Projects
None yet
Development

No branches or pull requests

3 participants