Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for custom JSON serializers #232

Open
jmg-duarte opened this issue Jun 8, 2022 · 3 comments
Open

Add support for custom JSON serializers #232

jmg-duarte opened this issue Jun 8, 2022 · 3 comments

Comments

@jmg-duarte
Copy link

Hello!

I have a use case that requires the serialization of uuid.UUIDs and Python's json cannot serialize them.
While I can str(uuid) before-hand, I think adding support for multiple json serializers is a plus (e.g. orjson is much faster and supports more types).

Would this be a feature you're interested in?

@abn
Copy link
Owner

abn commented Jun 10, 2022

I think it's a good idea to make it available. Both a better default scenario as well as the ability to specify serializers. Happy to review a PR, if this something you'd like to work on.

@jmg-duarte
Copy link
Author

Sorry for the delayed response. I'd be interested in working on this yes! Though I think I might need a bit of guidance.

I've searched through the code and seems to me that most of the PR might consist of simply adding a parameter to the aiohttp calls and any of it's dependents.
However, for the exceptions.py and request.py files, it doesn't seem to be that simple; as they don't really have an API that can be changed (IMO).

Let me know your thoughts!

@nettrino
Copy link

nettrino commented Nov 1, 2022

Also run into this using mashumaro.mixins.json's DataClassJSONMixin for datetime fields (e.g.,

@dataclass
class Test(DataClassJSONMixin):
    id: "str"
    createdAt: datetime = field(metadata={"deserialize": dateutil.parser.isoparse})
    updatedAt: datetime = field(metadata={"deserialize": dateutil.parser.isoparse})

and getting TypeError: Object of type datetime is not JSON serializable. Not sure if its something that could be hotpatched or requires a custom JSON serializer?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants