Open unratito opened 1 month ago
I over-optimized the serialization of dataclasses using orjson to such an extent that it led to unpleasant consequences that I overlooked 😅. In short, when we build the serialization code for W
, we build the code for turning dataclass A
into a dictionary with types supported by orjson, since A
is specified for inner
. At runtime for B
, this method will be called from the parent class A
without the specific field y
. I need to think more about what to do, since I don’t yet see any simple solutions other than getting rid of this optimization, which I wouldn’t want to do.
Here is another example of this issue:
from dataclasses import dataclass
from mashumaro import DataClassDictMixin
@dataclass
class A[T]:
x: T
@dataclass
class B[T](A):
y: int
@dataclass
class C(DataClassDictMixin):
z: A[int]
print(C(B(1, 2)).to_dict()) # {'z': {'x': 1}}
Looks like mashumaro is not the only one library which has this behavior 🤔
Description
When using mixins to serialize data classes to JSON, standard library
json
andorjson
give different results.What I Did
This code uses standard library
json
:And it prints these results:
While this equivalent code uses
orjson
:And it prints these other results: