yukinarit / pyserde

Yet another serialization library on top of dataclasses, inspired by serde-rs.
https://yukinarit.github.io/pyserde/guide/en
MIT License
732 stars 41 forks source link

Support more standard collections #83

Open yukinarit opened 3 years ago

yukinarit commented 3 years ago
davetapley commented 3 months ago

@yukinarit one more: namedtuple:

Point = namedtuple('Point', ['x', 'y'])

@dataclass
class Foo:
   p: Point

f = Foo(Point(1,2))
to_json(f)

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/python/3.12.2/lib/python3.12/site-packages/serde/json.py", line 75, in to_json
    to_dict(obj, c=cls, reuse_instances=reuse_instances, convert_sets=convert_sets), **opts
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/python/3.12.2/lib/python3.12/site-packages/serde/se.py", line 458, in to_dict
    return to_obj(  # type: ignore
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/python/3.12.2/lib/python3.12/site-packages/serde/se.py", line 386, in to_obj
    raise SerdeError(e) from None
serde.compat.SerdeError: Unsupported type: Point