mtth / avsc

Avro for JavaScript :zap:
MIT License
1.27k stars 147 forks source link

Invalid long value error for default value #406

Closed harshinim closed 1 year ago

harshinim commented 1 year ago

I have a backend that is returning a default value in the schema which is a very long integer. Custom long types has been implemented as per the below document

https://github.com/mtth/avsc/wiki/Advanced-usage#custom-long-types

I still get " invalid "long": 32503679999999000" error.

mtth commented 1 year ago

Hi @harshinim. This error is avsc protecting you from potentially invalid defaults in the parsed schema. The built-in JSON.parse does not handle long integers:

> JSON.parse('9007199254740995')
9007199254740996

To work around this you can use a custom JSON parser (for example json-bigint) to parse the schema. The only requirement from avsc's side is that the long type emitted by the parser be compatible with your custom long type.