Skip to content

Releases: Fatal1ty/mashumaro

v2.2

08 Apr 22:46
Compare
Choose a tag to compare

Changes

v2.1

06 Apr 21:21
Compare
Choose a tag to compare

Changes

v2.0.2

11 Mar 20:12
Compare
Choose a tag to compare

Changes

  • Fixed passing a value to serialize method of SerializationStrategy registered in Config: #44

v2.0.1

07 Mar 08:51
Compare
Choose a tag to compare

Changes

  • Fixed loading typing information for mypy #43

v2.0

02 Mar 08:08
Compare
Choose a tag to compare

Changes

  • Added support for collections.OrderedDict (3.7+) and collections.Counter types
  • Fixed passing serialize and deserialize field metadata options in Union and Optional types
  • SerializationStrategy is now a field option (backward incompatible change). See here for details.
  • Added ability to configure some options using inner Config class. See here for details.
  • Fixed typing problem on python 3.6. See #38.

v1.24

06 Feb 17:15
Compare
Choose a tag to compare

Changes

  • Added support for Union types. It's recommended to place more complex variant types at first place like Union[Dict[int, int], List[int]] not Union[List[int], Dict[int, int]]. When optional type validation is implemented it will be possible not to follow this rule.
  • It is now possible to use serialize and deserialize options for any third-party types and SerializableType classes if you need it for some reason.

v1.23

27 Jan 22:13
Compare
Choose a tag to compare

Changes

  • Added support for MyEnum(str, Enum): #33
  • Fixed using inner classes as field types:
@dataclass
class A(DataClassDictMixin):

    @dataclass
    class B(DataClassDictMixin):
        b: int

    a: int
    b: B

print(A.from_dict({'a': 1, 'b': {'b': 2}}))

v1.22

15 Jan 01:04
Compare
Choose a tag to compare

Changes

  • Support for hooks declared in superclasses
class Counter:
    deserialize = 0
    serialize = 0

    @classmethod
    def __pre_deserialize__(cls, d):
        Counter.deserialize += 1
        return d

    def __pre_serialize__(self):
        Counter.serialize += 1
        return self

@dataclass
class Derived(Counter, DataClassDictMixin):
    a: int

obj = Derived.from_dict({"a": 1})
obj.to_dict()

print(Counter.deserialize)  # 1
print(Counter.serialize)  # 1

v1.21

10 Jan 16:47
Compare
Choose a tag to compare

Changes

  • Added support for ipaddress types (#29)

v1.20

09 Jan 20:59
Compare
Choose a tag to compare

Changes

@dataclass
class User(DataClassJSONMixin):
    name: str
    password: str
    is_deserialized: bool = False
    counter: ClassVar[int] = 0

    @classmethod
    def __pre_deserialize__(cls, d: Dict[Any, Any]) -> Dict[Any, Any]:
        return {k.lower(): v for k, v in d.items()}

    @classmethod
    def __post_deserialize__(cls, obj: "User") -> "User":
        obj.is_deserialized = True
        return obj

    def __pre_serialize__(self) -> "User":
        self.counter += 1
        return self

    def __post_serialize__(self, d: Dict[Any, Any]) -> Dict[Any, Any]:
        d.pop("password")
        return d


user = User.from_json('{"NAME": "Name", "PASSWORD": "secret"}')
print(user)  # User(name='Name', password='secret', is_deserialized=True)
print(user.to_json())  # {"name": "Name", "is_deserialized": true}
print(user.counter)  # 1