You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Related: #1096. Not sure why the author closed the original issue as completed. Also not sure about your stance on discussions in closed issues so opening a new one
What is the feature you are proposing?
I think having a custom JSON.stringify option available would be beneficial.
Currently I sometimes have to do either
c.json(JSON.parse(jsonStringify(obj)astypeofobj),200)// note: `as typeof obj` to not lose types
which introduces overhead since Hono will make another JSON.stringify pass internally, or
Enabling customizing a JSON serializer is a good feature. We must consider whether it can keep the TypeScript types for RPC mode(TypedResponse). We also have to think about the API. I wouldn't say I like passing the serializer function to the construct of Hono since we want to keep the hono-base.ts minimum and don't want to pass many objects to the constructor of Context inside of it.
Related: #1096. Not sure why the author closed the original issue as completed. Also not sure about your stance on discussions in closed issues so opening a new one
What is the feature you are proposing?
I think having a custom JSON.stringify option available would be beneficial.
Currently I sometimes have to do either
which introduces overhead since Hono will make another
JSON.stringify
pass internally, orwhich isn't the most ergonomic to type (and also loses typed response)
as workarounds
I'm thinking as an initialization option when initializing the Hono app, we can pass a custom stringifier
that would then be used here:
hono/src/context.ts
Line 829 in bdaaa7f
A possible footgun migth be that the replacer function could change the types, but so could the normal JSON.stringify, e.g.
which a safe number replacer could "fix" by replacing Infinity with
Number.MAX_SAFE_INTEGER
depending on the applicationThe text was updated successfully, but these errors were encountered: