Hello, folks. In a library I'm working on, I have ...
# javascript
h
Hello, folks. In a library I'm working on, I have a class holding a map, and
toString()
on that class should return
JSON.stringify(theMap)
. But that won't work since js maps have this prototype thing in them (at least I think that's why), and so there are circular references in js runtime. Has anyone got a good idea about how I could convert the map into something that
JSON.stringify()
would like?
r
Hi Hallvard, I think https://github.com/Kotlin/kotlinx.serialization might be helpful
h
Yeah, and I wish to go there. I even prepared my code for it, in a branch for a version 2. But for different reasons, I also need a version 1 to work without the built-in kotlin serialization ...
r
So you could use
replacer
parameter of
JSON.stringify
to handle cyclic references using indexes or something similar and keep another object with this information. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#Parameters
h
Nice, @Roman Artemev [JB]. Thanks. I'll give it a try.