Skip to content

Conversation

@ouatu-ro
Copy link
Contributor

Adds a general serde that can handle serialisation for both Pydantic objects and regular JSON objects. Tested for workflows, services and virtual objects.

Related to #45

- Introduce GeneralSerde to handle both Pydantic BaseModel instances and regular JSON objects.
- Use model_dump_json for Pydantic models, falling back to json.dumps for non-Pydantic objects.
- Maintain consistency with existing serde implementations.
Copy link
Contributor

@igalshilman igalshilman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @ouatu-ro,
great stuff!

I've left few comments for you to address, after that really looks good to me to merge!

- Updated imports and default serializer/deserializer in **context**, handler, object, **server_context**, service, and workflow modules.
- DefaultSerde provides a unified approach for JSON serialization/deserialization, ensuring compatibility with both Pydantic models and standard JSON objects.
@github-actions
Copy link

github-actions bot commented Mar 18, 2025

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@ouatu-ro
Copy link
Contributor Author

I have read the CLA Document and I hereby sign the CLA

@ouatu-ro
Copy link
Contributor Author

recheck

@ouatu-ro
Copy link
Contributor Author

Renamed GeneralSerde to DefaultSerde which is now also used inside Context and ServerInvocationContext.run.
The DefaultSerde check for Pydantic should be very light, as it uses isinstanceof primitive and shouldn't generate performance issues, while adding the same automatic Serde on ctx as on the regular handlers.

Copy link
Contributor

@igalshilman igalshilman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Amazing, looks good to me!

@igalshilman igalshilman merged commit ad78d56 into restatedev:main Mar 18, 2025
4 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Mar 18, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants