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

Nested types involving lists lost in verbose serialization/deserialization #155

Open
milkshakeiii opened this issue Jan 31, 2022 · 1 comment

Comments

@milkshakeiii
Copy link

milkshakeiii commented Jan 31, 2022

import jsons
from dataclasses import dataclass
from typing import List

@dataclass
class GenericStrategy():
    pass

@dataclass
class GoodStrategy(GenericStrategy):
    pass

@dataclass
class Containee():
    strategy: GenericStrategy

@dataclass
class Container():
    containees: List[Containee]

    
a = Container(containees=[Containee(strategy=GoodStrategy())])
b = jsons.dumps(a, verbose=True)
c = jsons.loads(b)

Based on my understanding, the object c at the end should have a GoodStrategy in c.containees[0].strategy, but instead it has a GenericStrategy. I believe this is a minimal example, nesting without using List doesn't seem to cause the problem.

I am using a workaround for my project. Just wanted to let you know. Thanks for making this library.

@milkshakeiii milkshakeiii changed the title Nested types involving lists lost in verbose serialization Nested types involving lists lost in verbose serialization/deserialization Jan 31, 2022
@milkshakeiii
Copy link
Author

milkshakeiii commented Feb 16, 2022

Another (what I believe to be a) problem with lists:


import jsons
from dataclasses import dataclass
from typing import List, Dict

@dataclass
class Container:
    contents: Dict[str, List[int]]

dictionary = {"key": [1, 2, 3]}
container = Container(contents=dictionary)
serialized = jsons.dump(container, verbose=True)
deserialized = jsons.load(serialized)

Produces an error.

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