Add support to use external JSON parser
PeterKnego opened this issue · 1 comments
TypedJSON by default uses JSON parser provided by browser. The problem with the default parser is that it mangles BigInt values. So there is no option to write a TypedJSON deserializer that would properly handle bigint values, as they are already rounded to Javascript numbers.
Solution: provide a way to define external parser during the TypedJson setup. There are parsers that properly handle bigint numbers in JSON, e.g. json-bigint.
Note: there is already a way to serialize objects with bigint fields: TypedJSON prvides toPlainJson
function that produces plain JSON objects, that can then be serialized with parsers that properly handle bigint numbers in JSON, e.g. json-bigint
.
I was able to resolve proper BigInt parsing by first using json-bigint
parser and then run returned object through TypedJSON.parse()
.
let jsonObj = JSONbig.parse(jsonString);
let value: RES | undefined = TypedJSON.parse(jsonObj, responseType)