lidatong / dataclasses-json

Easily serialize Data Classes to and from JSON
MIT License
1.36k stars 153 forks source link

[FEATURE] V1 - Type coercions feature #474

Open george-zubrienko opened 1 year ago

george-zubrienko commented 1 year ago

Description

In v0 this PR aligned lib behaviour with marshmellow, but effectively triggered a couple of unexpected consequences:

Possible solution

First of all, we should add a flag for implicit coercions:

[tool.dataclasses_json]
coerce_builtins = True

Second, we should do a follow-up discussion re coercion behaviours in from_dict, IMO this should differ from from_json behaviour because from_dict argument carries type information, while from_json has to work with a string.

Alternatives

N/A

Context

Problem discovered in https://github.com/lidatong/dataclasses-json/issues/466