-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add support for nested serializers, e.g., a dict with dfs
- Loading branch information
Showing
5 changed files
with
76 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,20 @@ | ||
import json | ||
|
||
from . import default_serializer, numpy_serializer, pandas_serializer | ||
from .framework import Serializer, datetime_encoder, serializers | ||
from .framework import Serializer, custom_encoder, serializers | ||
|
||
|
||
def serialize(obj, serializer_name="default"): | ||
serializer = serializers.get(type(obj), serializers.get(serializer_name)) | ||
if serializer is None: | ||
raise ValueError(f"No serializer registered for object of type {type(obj)}") | ||
return json.dumps(serializer.serialize(obj), default=datetime_encoder) | ||
return json.dumps(serializer.serialize(obj), default=custom_encoder) | ||
|
||
|
||
def deserialize(payload, serializer_name="default"): | ||
payload = json.loads(payload) | ||
serializer_name = payload.get("serializer", serializer_name) | ||
serializer = serializers.get(serializer_name, serializers.get(serializer_name)) | ||
serializer = serializers.get(serializer_name) | ||
if serializer is None: | ||
raise ValueError(f"No serializer registered with name '{serializer_name}'") | ||
return serializer.deserialize(payload) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters