We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
from_json
I tried adapting one example from the doc to generic dataclasses.
The following example fails to parse the Minions as such.
Minion
from dataclasses import dataclass from dataclasses_json import dataclass_json from typing import TypeVar, Generic, List T = TypeVar("T", str, int) @dataclass_json @dataclass(frozen=True) class Minion(Generic[T]): name: T @dataclass_json @dataclass(frozen=True) class Boss(Generic[T]): minions: List[Minion[T]] boss = Boss([Minion("evil minion"), Minion("very evil minion")]) print(Boss.from_json(boss.to_json()))
This is the result, as you can see the minions are still dicts, not Minions
dict
Boss(minion1={'name': 'evil minion'}, minion2={'name': 'very evil minion'})
Am I doing something wrong?
The text was updated successfully, but these errors were encountered:
My current best workaround is to specify a decoder like this:
from dataclasses import dataclass, field from dataclasses_json import dataclass_json, config @dataclass_json @dataclass(frozen=True) class Boss(Generic[T]): minion: Minion[T] = field(metadata=config(decoder=Minion.from_dict))
Sorry, something went wrong.
Target of #442
No branches or pull requests
I tried adapting one example from the doc to generic dataclasses.
The following example fails to parse the
Minion
s as such.This is the result, as you can see the minions are still
dict
s, notMinion
sAm I doing something wrong?
The text was updated successfully, but these errors were encountered: