How to serialize / deserialize bigints in request bodies in NestJS?

Viewed 98

In the project I'm working on, specification states that bodies of request will have bigints literals instead of strings, e.g:

{ 
  total_supply: 96585829199248589999910000000000000000000
}

My DTO changed to:

 total_supply?: bigint

Of course I expected this to fail at first try, since the default JSON.stringify wont handle those bigints:


    TypeError: Do not know how to serialize a BigInt
        at JSON.stringify (<anonymous>)

      at new Request (../node_modules/light-my-request/lib/request.js:98:20)
      at ../node_modules/light-my-request/index.js:110:19
      at doInject (../node_modules/light-my-request/index.js:109:12)
      at Chain.<computed> [as then] (../node_modules/light-my-request/index.js:199:23)

How I can replace the JSON handling routines with proper ones (e.g: https://www.npmjs.com/package/@randlabs/json-bigint) in NestJS? Maybe using interceptors? I would like to do it in a "NestJS-way" , if it's possible.

0 Answers
Related