Closed gvashishtha closed 4 months ago
This is fixed in https://github.com/Fatal1ty/mashumaro/pull/194 and will be available in the next release.
Until a new version released, a workaround is to register pass_through
serialization strategy:
@dataclass
class Foo(DataClassJSONMixin):
x: int | float
_x: str = field(init=False, repr=False)
class Config(BaseConfig):
serialization_strategy = {
int: {"serialize": pass_through},
float: {"serialize": pass_through}
}
Description
I am trying to get mashumaro to correctly handle a union type that can be either
int
orfloat
. But when I callto_json()
the value is automatically cast to an integerWhat I Did