-
Notifications
You must be signed in to change notification settings - Fork 153
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
[BUG] from_json of class with attribute of list of types which inherit basic types results in wrong result #485
Comments
I am not sure what is happening here:
|
Yes, the reason I am writing to a file in this example is that When this is written to a file, the text: In short, the writing into a file is not required and the following will also reproduce this bug: from dataclasses import dataclass
from dataclasses_json import DataClassJsonMixin
class Name(str):
...
@dataclass
class Person(DataClassJsonMixin):
names: list[Name]
if __name__ == '__main__':
js = '{"names": ["John Doe"]}'
print(isinstance(Person.from_json(js).names[0], Name)) # prints: False |
I'll retest this on latest commit tomorrow to see if this is some similar issue with 3.10 as with self-types |
Description
I have a
dataclass
that holds an attribute of list (if names was type of name and not list of Name, issue would not reproduce) of a class that inherits the basic type:string
.When creating an instance of this class, converting it into json, writing said json to a file and later reading it and re-creating the object from it, the object structure is not identical to the previous object structure.
The attribute of list that contains objects which inherit the basic type creates the list objects as the basic type instead of their expected type.
Code snippet that reproduces the issue
Describe the results you expected
As the original type was indeed Name (before being written into the file) I expected the object after reading the json to also be Name
Python version you are using
3.10
Environment description
Standard clean env. only used
pip install dataclasses-json
The text was updated successfully, but these errors were encountered: