Serialization of node and connector

Hi,

I can serialize the whole diagram right now using the following code in js:

const jsonData = diagram.saveDiagram();

But my need is to  serialize a particular node (all it sproperties as i am in a drawing mode) and a connector of a diagram, something like 

diagram.nodes[0].saveNode().

I have tried to do it like this:

const jsonData = JSON.stringify(diagram.nodes[0]);

const jsonData = JSON.stringify(diagram.connectors[0]);

But I have a js error:

Uncaught TypeError: Converting circular structure to JSON

    --> starting at object with constructor 't'

    | property 'properties' -> object with constructor 'Object'

    | property 'shape' -> object with constructor 't'

    --- property 'parentObj' closes the circle

    at JSON.stringify (<anonymous>)


Thnaks for your help,

regards,

Laurent


3 Replies 1 reply marked as answer

GG Gowtham Gunashekar Syncfusion Team July 28, 2021 01:00 PM UTC

Hi Laurent 
 
On the further analysis of the shared details, we understood that you want to serialize the specific part of the diagram, but we have options to serialize the entire diagram as the JSON and we don’t have any API to serialize a node or connector. We suggest you use the getNodeObject and getConnectorObject API to get the deep cloned version of node and connector respectively to avoid the circular reference error while stringify the node.  
 
Code snippet: 
// to stringify the node 
const jsonData = JSON.stringify(diagram.getNodeObject(diagram.nodes[0].id))  
 
// to stringify the connectors  
 
const jsonData = JSON.stringify(diagram.getConnectorObject(diagram.connectors[0].id))  
 
Regards  
Gowtham.   
 


Marked as answer

LA Laurent July 30, 2021 11:44 AM UTC

Thanks for your answer.

That works fine.


regards,



SS Swetha Srikumar Syncfusion Team August 2, 2021 08:40 AM UTC

Hi Laurent, 
 
Most welcome. Please let us know if you need any other assistance. 
 
Regards, 
Swetha 


Loader.
Up arrow icon