Mashumaro

Latest version: v3.15

Safety actively analyzes 682457 Python packages for vulnerabilities to keep your Python projects secure.

Scan your dependencies

Page 9 of 12

1.21

Changes
--------

* Added support for `ipaddress` types (https://github.com/Fatal1ty/mashumaro/pull/29)

1.20

Changes
--------

* Added serialization hooks https://github.com/Fatal1ty/mashumaro#serialization-hooks

python
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

1.19

Changes
--------

* Added support for `serialize` option:

python
dataclass
class A(DataClassDictMixin):
dt: datetime = field(
metadata={
"serialize": lambda v: v.strftime('%Y-%m-%d %H:%M:%S')
}
)

1.18

Changes
--------
* Fixed weird `TypeError` exception that was thrown instead of `MissingField` in case when `field` doesn't have `default` argument
* Added ability to change deserialization method with `metadata` argument. See [here](https://github.com/Fatal1ty/mashumaro#using-field-metadata) for details.

1.17

Changes
--------
* Support for all types from `pathlib`
* Variable annotated with a class derived from `os.PathLike` will be deserialized into an instance of that class
* Variable annotated with `os.PathLike` will be deserialized into an instance of `PurePath` class: `PurePosixClass` on posix, `PureWindowsPath` in windows

1.16

Changes
--------
* Raise `InvalidFieldValue` with details in case deserialization fails.

Page 9 of 12

© 2024 Safety CLI Cybersecurity Inc. All Rights Reserved.