aiographql-client icon indicating copy to clipboard operation
aiographql-client copied to clipboard

Add support for custom JSON serializers

Open jmg-duarte opened this issue 2 years ago • 3 comments

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?

jmg-duarte avatar Jun 08 '22 13:06 jmg-duarte

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.

abn avatar Jun 10 '22 11:06 abn

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!

jmg-duarte avatar Jun 15 '22 18:06 jmg-duarte

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?

nettrino avatar Nov 01 '22 12:11 nettrino