Using GeometryBase.FromJson / GeometryBase.ToJson between Versions

Good evening Rhino fans,

I’m working on a plugin called Crash for multi-user Rhino, and I’ve finished up most of it now, hoping to release it soon. Somewhere within the last 6 months something seems to have changed when it comes to the JSON to/from inside Rhino. (I could of course be mistaken but I’m pretty sure).

Previously Crash could serialize any Rhino Geometry to JSON, send it to the server and every other instance of Rhino would receive it and de-serialize it correctly. I tried today but I got lots of SerializationExceptions.

{ "version":10000,

If I send some JSON from Rhino 8 and receive it on Rhino 7, it doesn’t work, if I change the archive3dm version from 80 to 70 it does de-serialize correctly. I obviously don’t want to do this as it’s quite flakey. Somewhere inside of the C++ core of Rhino it takes this info and creates an object, and I’m assuming there’s some checks based on the archive3dm version. And likely inside Rhino 7 it doesn’t have an if catch for Rhino 8.

I’m using Rhino 7.34.23267 (Win) and Rhino 8.0.23304 (Mac)

if I can’t figure this one out I have to create a wrapper for every geometry type and transmit it that way which would take me quite some time, and I’d much rather use the built in JSONifier.

– cs

Whilst writing this I managed to solve this, but I figured it was worth still worth posting as I couldn’t find an answer to this elsewhere.

geometry?.ToJSON(new SerializationOptions { RhinoVersion = 70});
1 Like