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

Generic deserialization does not work when dataclass is passed in generic arg #464

Open
yukinarit opened this issue Jan 14, 2024 · 0 comments
Labels
bug Bug report or fix

Comments

@yukinarit
Copy link
Owner

from typing import Generic, TypeVar
from serde import serde Trailing whitespace
from serde.json import from_json , to_json

T = TypeVar("T")

@serde
class Bar(Generic[T]):
    inner: T

@serde
class Foo(Generic[T]):
    inner: T


# This works
f1 = Foo(10)
json = to_json(f1)
print(json)
print(from_json(Foo[int], json))  # Prints Foo(inner=10)

# This does not work
f2 = Foo(Bar(10))
json = to_json(f2)
print(json)

# Foo(inner=Bar(inner=10)) is expected but prints Foo(inner={'inner': 10})
print(from_json(Foo[Bar[int]], json))
@yukinarit yukinarit added the bug Bug report or fix label Jan 14, 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

1 participant