Class JSONHelper
java.lang.Object
com.marginallyclever.nodegraphcore.json.RectangleDAO4JSON
public class JSONHelper
extends java.lang.Object
Convenience methods for serializing and de-serializing objects in this package.
- Since:
- 2022-02-01
-
Constructor Summary
Constructors Constructor Description JSONHelper()
-
Method Summary
Modifier and Type Method Description static Node
deepCopy(Node source)
Creates a deep copy of the givenNode
using json serialization/deserializationstatic NodeGraph
deepCopy(NodeGraph graph)
Creates a deep copy of the givenNodeGraph
using json serialization/deserializationstatic NodeConnection
deserializeNodeConnection(com.google.gson.JsonElement jsonElement, NodeGraph dstGraph)
Used for de-serializing a singleNodeConnection
from aJsonElement
.static void
deserializeNodeConnections(com.google.gson.JsonElement jsonElement, NodeGraph dstGraph)
static void
deserializeNodeVariable(NodeVariable<?> variable, com.google.gson.JsonElement jsonElement)
Used for de-serializing a singleNodeVariable
from aJsonElement
static void
deserializeNodeVariables(java.util.Collection<NodeVariable<?>> variables, com.google.gson.JsonElement jsonElement)
static com.google.gson.Gson
getDefaultGson()
Returns the defaultGson
.static com.google.gson.GsonBuilder
getDefaultGsonBuilder()
Returns the defaultGsonBuilder
.static void
registerTypeAdapters(com.google.gson.GsonBuilder builder)
Registers the NodeGraph classes with aGsonBuilder
.static com.google.gson.JsonElement
serializeNodeConnection(NodeConnection connection)
Used for serializing a singleNodeConnection
to aJsonElement
static com.google.gson.JsonElement
serializeNodeConnections(java.util.Collection<NodeConnection> nodeConnections)
static com.google.gson.JsonElement
serializeNodeVariable(NodeVariable<?> variable)
Used for serializing a singleNodeVariable
to aJsonElement
static com.google.gson.JsonElement
serializeNodeVariables(java.util.Collection<NodeVariable<?>> variables)
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Constructor Details
-
JSONHelper
public JSONHelper()
-
-
Method Details
-
getDefaultGson
public static com.google.gson.Gson getDefaultGson()Returns the defaultGson
.- Returns:
- the default
Gson
.
-
getDefaultGsonBuilder
public static com.google.gson.GsonBuilder getDefaultGsonBuilder()Returns the defaultGsonBuilder
.- Returns:
- the default
GsonBuilder
.
-
registerTypeAdapters
public static void registerTypeAdapters(com.google.gson.GsonBuilder builder)Registers the NodeGraph classes with aGsonBuilder
.- Parameters:
builder
- theGsonBuilder
.
-
deepCopy
Creates a deep copy of the givenNodeGraph
using json serialization/deserialization -
deepCopy
Creates a deep copy of the givenNode
using json serialization/deserialization -
serializeNodeConnections
public static com.google.gson.JsonElement serializeNodeConnections(java.util.Collection<NodeConnection> nodeConnections)- Parameters:
nodeConnections
- theCollection
ofNodeConnection
s to serialize- Returns:
- a
JsonElement
representing the list ofNodeConnection
s
-
deserializeNodeConnections
public static void deserializeNodeConnections(com.google.gson.JsonElement jsonElement, NodeGraph dstGraph)- Parameters:
jsonElement
- theJsonElement
to read theCollection
ofNodeConnection
s fromdstGraph
- the destinationNodeGraph
, where the connections will be added
-
serializeNodeConnection
Used for serializing a singleNodeConnection
to aJsonElement
- Parameters:
connection
- theNodeConnection
to serialize- Returns:
- a
JsonElement
representing theNodeConnection
-
deserializeNodeConnection
public static NodeConnection deserializeNodeConnection(com.google.gson.JsonElement jsonElement, NodeGraph dstGraph)Used for de-serializing a singleNodeConnection
from aJsonElement
. This method only performs the deserialization and doesn't add the connection to the graph, that is handled bydeserializeNodeConnections(com.google.gson.JsonElement, com.marginallyclever.nodegraphcore.NodeGraph)
- Parameters:
jsonElement
- theJsonElement
to de-serialize theNodeConnection
fromdstGraph
- the destinationNodeGraph
- Returns:
- the
NodeConnection
-
serializeNodeVariables
public static com.google.gson.JsonElement serializeNodeVariables(java.util.Collection<NodeVariable<?>> variables)- Parameters:
variables
- theCollection
ofNodeVariable
s to serialize- Returns:
- a
JsonElement
representing theCollection
ofNodeVariable
-
deserializeNodeVariables
public static void deserializeNodeVariables(java.util.Collection<NodeVariable<?>> variables, com.google.gson.JsonElement jsonElement)- Parameters:
variables
- theCollection
ofNodeVariable
s to deserialize into, MUST contain all of theNodeVariable
s required already.jsonElement
- the element to de-serialize the nodes from
-
serializeNodeVariable
Used for serializing a singleNodeVariable
to aJsonElement
- Parameters:
variable
- theNodeVariable
s to serialize- Returns:
- a
JsonElement
representing theNodeVariable
-
deserializeNodeVariable
public static void deserializeNodeVariable(NodeVariable<?> variable, com.google.gson.JsonElement jsonElement)Used for de-serializing a singleNodeVariable
from aJsonElement
- Parameters:
variable
- theNodeVariable
s to deserialize intojsonElement
- the element to de-serialize the nodes from
-