Error "Do not know how to serialize a BigInt at JSON.stringify"
Galienna opened this issue · 1 comments
Galienna commented
I could not have guessed that would have worked at all. Our support to BigInt is limited to integers: https://github.com/fastify/fast-json-stringify/blob/4d990f660bca9c3b3eb98f086a04c80ade428277/test/bigint.test.js.
Originally posted by @mcollina in #491 (comment)
Hello,
If the serialization of BigInt to integer is supported, I think there's something wrong. I get the error "TypeError: Do not know how to serialize a BigInt at JSON.stringify" running this simple code with fastify 4.2.1:
const fastify = require('fastify');
const server = fastify({
requestIdHeader: 'x-request-id',
genReqId: uuidv4,
ignoreTrailingSlash: true,
trustProxy: true
});
server.route({
method: 'GET',
url: '/stats',
handler: function () {
return [{count: 154n, createdAt: '2022-01-01'}]
},
schema: {
$id: 'get-stats',
response: {
200: {
type: 'array',
items: {
count: {
type: 'integer',
minimum: 0
},
createdAt: {
type: 'string'
}
}
}
}
}
});
server.listen({port: 8080, host: '0.0.0.0'});
Am I doing something wrong ?
Galienna commented
Turns out I'm dumb or exhausted \o/
I was so focused on the serialization error that I missed the bad definition of my item schema.
Sorry...