Pluggable Object converters

By João Gonçalves on 10 Feb 2017

The Object type of the platform is able to hold reference to both platform derived types (Lists, String, Structures, etc) and plain javascript objects. For this reason this can be used for many ends such has passing platform objects from action to action and even to javascript nodes.

Many times there's a need to pass some object/data to external javascript code with a specific structure and the current solutions that I am aware are:

  • If the structure is known, manually create a javascript object with the desired structure and set the respected values
  • Use JSON.stringify() on a platform Object and later JSON.parse(). This adds unnecessary overhead 
  • Same as previous but with serialize/deserialize actions from the platform

And when we want to get data from external code into platform's context types we have:

  • A defined Structure that knows how to parse objects from JSON

My idea would be to have a pluggable system for type converters in a way that the user defines how a specific type should be converted from plain javascript to a platform type. This, coupled with would make a powerful toolset.

Carlos Xavier13 Feb 2017

Wouldn't it be simpler if you could use Entities, Structures and Lists as parameters for JavaScript nodes? The Entities and Structures could be converted to plain JavaScript objects and the Lists to JavaScript arrays. I don't see the need for custom conversions. Would it be enough for your needs?

João Gonçalves13 Feb 2017

Being able to use Entities, Strucutures and Lists would be a starting point but currently Entities are only able to be initialized by giving a JSON object, what I am proposing is to have a similar functionality that would allow initializing Entities from a javascript plain Object instead of a JSON.

Additionally this would also allow for functional transformation while converting data