Closed
Description
Is your feature request related to a problem? Please describe.
Our use of https://github.com/konradhalas/dacite is too primitive. It only supports to/from the object itself, not collections, optional, etc.
Describe the solution you'd like
All of the following should be supported via type hints:
MyDataClass
List[MyDataClass]
,Set[MyDataClass]
, other collections, etcMapping[str, MyDataClass]
,Dict[str, MyDataClass]
, other dicts, etcUnion[MyDataClass1, MyDataClass2]
,Union[List[int], Dict[str, MyDataClass]]
, etcOptional[MyDataClass1]
,Optional[List[Dict[str, MyDataClass]]]
, etc
Here are the libraries found so far:
- https://github.com/konradhalas/dacite
- What we currently use
- No top-level collection, mapping, etc support
- Could be good base to build off of
- https://github.com/lidatong/dataclasses-json
- No support for non-decorator/non-mixin use (see issue on their repo numbered 243)
- Requires marshmallow
- https://github.com/rnag/dataclass-wizard
- Not the most popular (yet?)
- Does not require inheritance/mixin use
- Still requires us to figure out whether it's a dict or list or what not
- https://github.com/lovasoa/marshmallow_dataclass
- Requires marshmallow (which is a popular library and therefore may clash with other users' marshmallow needs)
- Seems to be the layer backing dataclasses-json
- Will still have to determine data types expected
We should probably support customization via instance.to_json()
/instance.to_dict()
and Class.to_json()
/Class.to_dict()
. This means those using some of those other libraries will work automatically.
Needs investigation...