Skip to content

Conversation

123NeNaD
Copy link
Contributor

Checklist

This PR fixes an issue where custom object formats failed during serialization when nested inside a Union type (check #779).

Previously, the fjs_type keyword was used to support JavaScript Date objects, since Ajv does not natively validate them. This PR extends that logic to all objects implementing a .toJSON() method, ensuring they are serialized correctly (for example, MongoDB ObjectId).

Key Points

✅ Extends fjs_type handling beyond Date to any .toJSON()-capable object.
✅ Ensures correct serialization for custom formats like ObjectId.
✅ Backward compatibility is preserved since Date objects already implement .toJSON() (returning an ISO string).

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

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

lgtm

@mcollina mcollina merged commit 2b37f1d into fastify:main Oct 3, 2025
14 checks passed
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

Successfully merging this pull request may close these issues.

2 participants