Fork me on GitHub
#transit
<
2023-11-28
>
Mark Wardle22:11:01

Hi all. I have used specific transit handlers for specific types/classes of object previously - is there a way of taking special care of long values in a map - either by virtue of me adding metadata to that specific value, or by virtue of the key used in that map? Do I override handling of all maps and add processing of the keys, or is there a better approach? I have an issue with clojurescript not handling very large long values that would be awkward to fix at my API level, but fixing via transit might work. All advice gratefully received!

p-himik22:11:15

Instances of clojure.lang.BigInt (i.e. number literals followed by N, as in 7N) are serialized with their own tag. If you can live comfortably with BigInts, you can simply switch to those. Alternatively, it might be possible to override the default long reader on the CLJS side so that it returns instances of js/BigInt.

p-himik22:11:15

> issue with clojurescript not handling very large long values To be clear, that's not CLJS, that's JS. CLJS cannot possibly have a way around that, apart from implementing a complete number stack on its own and changing every single aspect of the internal machinery and interop.

Mark Wardle07:11:57

That’s a great idea thank you. If I preprocess the data to be outputted to coerce the values to BigInt then I can leverage that, and not have to change other server side machinery to deal with strings.