Yet another serialization library on top of dataclasses, inspired by serde-rs.
New custom class (de)serializer allows to extend pyserde to support third party types in a neat and robust way. Also custom global (de)serializer is a game changer to allow sharing and reusing custom serializers across different python projects. See custom class serializer and custom global serializer for more information.
e.g. Implementing serializer for datetime
and int
class Serializer:
# Custom serializer for "datetime"
@overload
def serialize(self, value: datetime) -> str:
return value.strftime("%d/%m/%y")
# Custom serializer for "int"
@overload
def serialize(self, value: int) -> Any:
return str(value)
....
Full Changelog: https://github.com/yukinarit/pyserde/compare/v0.12.7...v0.13.0
skip_if
causing serialization of a recursive type to be O(2**n)
instead of O(n)
by @gschaffner in https://github.com/yukinarit/pyserde/pull/452
Full Changelog: https://github.com/yukinarit/pyserde/compare/v0.12.6...v0.12.7
Full Changelog: https://github.com/yukinarit/pyserde/compare/v0.12.5...v0.12.6
Full Changelog: https://github.com/yukinarit/pyserde/compare/v0.12.4...v0.12.5
Full Changelog: https://github.com/yukinarit/pyserde/compare/v0.12.3...v0.12.4
Full Changelog: https://github.com/yukinarit/pyserde/compare/v0.12.2...v0.12.3
kw_only
by @m472 in https://github.com/yukinarit/pyserde/pull/413
frozen
and kw_only
support by @yukinarit in https://github.com/yukinarit/pyserde/pull/415
Full Changelog: https://github.com/yukinarit/pyserde/compare/v0.12.1...v0.12.2
Full Changelog: https://github.com/yukinarit/pyserde/compare/v0.12.0...v0.12.1
This example works correctly now
@serde
@dataclass
class Foo:
a: int
@serde
@dataclass
class Bar:
a: int
bar = Bar(10)
s = to_json(bar)
print(s)
print(from_json(Union[Foo, Bar], s))
However, This will introduce a breaking change!! The default behaviour when you pass Union directly was "Untagged" until v0.11.1, but since v0.12.0 it is "ExternalTagging".
The following code prints {"a": 10}
until v0.11.1, but prints {"Bar": {"a": 10}}
since v0.12.0
print(to_json(bar))
For more information about Union, please see the docs
Full Changelog: https://github.com/yukinarit/pyserde/compare/v0.11.1...v0.12.0
Full Changelog: https://github.com/yukinarit/pyserde/compare/v0.11.0...v0.11.1