elnabo / json2object

Type safe Haxe/JSON (de)serializer
MIT License
66 stars 17 forks source link

Possible to use Writer for producing plain js object, bypassing Json stringifyer? #73

Closed cambiata closed 3 years ago

cambiata commented 3 years ago

Hi Guillaume!

I want to find a solution for passing Haxe objects to/from WebWorkers, and because of the restrictions of the structured clone algorithm https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm, Haxe enums, maps etc have to be "serialized" to js objects containing only object literals.

Is there a way to use json2object without the "json" stringify step, only producing a simple js object? And the reverse, for recreating the Haxe object..?

Best! / Jonas

ibilon commented 3 years ago

Why do you need to have a native js object as the intermediary step? With json2object you can convert your object to a json string which pass the structured clone algorithm and therefor can be sent to/from a webworker, then convert it back to an haxe object.

cambiata commented 3 years ago

Yes, ibilion, you're right - I don't really need that. But I'm thinking that not having to convert to/from string might shave some tiny processing and time...

ibilon commented 3 years ago

Maybe, but then that time will be used by the javascript engine to clone the structure ;)

cambiata commented 3 years ago

Good point! :-)