lidatong / dataclasses-json

Easily serialize Data Classes to and from JSON
MIT License
1.34k stars 150 forks source link

Fixes catchall inheritance issue #500

Closed jasonrock-a3 closed 7 months ago

jasonrock-a3 commented 7 months ago

Fixes an issue caused because get_type_hints behaves differently for classes and objects leading to serialization of subclasses that inherit from a dataclass with CatchAll to fail.

Added test will break in the current 0.6.2 release.

def test_undefined_inheritance():
    @dataclass_json(undefined=Undefined.INCLUDE)
    @dataclass
    class TestInternalConfig:
        options: CatchAll = None
        val: str = "bar"
        val2: int = 0

    @dataclass_json
    @dataclass
    class TestInternalExtendConfig(TestInternalConfig):
        val: str = "baz"

    tie = TestInternalExtendConfig()
    tie.to_dict()

Closes #499

jasonrock-a3 commented 7 months ago

Just going to tag people who were on the initial change to see if this could get moved ahead since it does actually cause some issues.

@2ynn @george-zubrienko

jasonrock-a3 commented 7 months ago

No problem, thanks for the quick merge

2ynn commented 7 months ago

:/ sorry for that!