Skip to content

feat: document and test the objectMechanism option of fast-json-stringify v7.3.0 - #102

Merged
Tony133 merged 2 commits into
mainfrom
feat/object-mechanism-option
Nov 6, 2026
Merged

Tony133 merged 2 commits into
mainfrom
feat/object-mechanism-option

Conversation

@Tony133

@Tony133 Tony133 commented Nov 5, 2026 •

Copy link
Copy Markdown
Member

Proposal:

Follow-up to fastify/fast-json-stringify#906, as discussed there and in fastify/fastify#6507.

Context:

fast-json-stringify@7.3.0 added objectMechanism: 'native': the serializer projects the payload into schema-shaped objects and delegates to JSON.stringify, so on Node.js 25+ V8 stays on its fast path while the response schema is still applied. Output is identical to the default mechanism; the option is a no-op on Node.js < 25.

Change:

The compiler already forwards serializerOpts as-is, and the types import Options from fast-json-stringify, so nothing in the code needs to change. This PR makes the option usable and visible:

  • fast-json-stringify dependency bumped to ^7.3.0, so objectMechanism is accepted and typed;
  • README: short section with the serializerOpts: { objectMechanism: 'native' } example;
  • tests: an invalid objectMechanism throws through the compiler (proves the option reaches fast-json-stringify on every runtime), 'native' and 'default' give the same output on an input carrying an undeclared property and a Date, and a Fastify integration test with serializerOpts: { objectMechanism: 'native' };
  • type tests: 'native' and 'default' accepted, an arbitrary string rejected.

Why now:

This is the first step towards proposing 'native' as the default in Fastify v6; it lets users opt in on v5 today.

Note:

  • This raises the dependency floor to fast-json-stringify@^7.3.0 and documents a new option, so it should go out as a minor release (semver-minor).
  • min-release-age=7 rejects fast-json-stringify@7.3.0 until Nov 12. The second commit temporarily excludes it from the check (min-release-age-exclude, npm >= 11.17), with a dated comment in .npmrc; I'll remove those two lines after the 12th, or drop the commit now if you'd rather wait.

@Tony133
Tony133 marked this pull request as ready for review November 5, 2026 16:32
@Tony133
Tony133 requested a review from mcollina November 5, 2026 17:36

@mcollina mcollina left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

lgtm

@Tony133
Tony133 merged commit 73690b3 into main Nov 6, 2026
51 of 54 checks passed
@Tony133
Tony133 deleted the feat/object-mechanism-option branch November 6, 2026 16:07
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