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 NodedeepCopy(Node source)Creates a deep copy of the givenNodeusing json serialization/deserializationstatic NodeGraphdeepCopy(NodeGraph graph)Creates a deep copy of the givenNodeGraphusing json serialization/deserializationstatic NodeConnectiondeserializeNodeConnection(com.google.gson.JsonElement jsonElement, NodeGraph dstGraph)Used for de-serializing a singleNodeConnectionfrom aJsonElement.static voiddeserializeNodeConnections(com.google.gson.JsonElement jsonElement, NodeGraph dstGraph)static voiddeserializeNodeVariable(NodeVariable<?> variable, com.google.gson.JsonElement jsonElement)Used for de-serializing a singleNodeVariablefrom aJsonElementstatic voiddeserializeNodeVariables(java.util.Collection<NodeVariable<?>> variables, com.google.gson.JsonElement jsonElement)static com.google.gson.GsongetDefaultGson()Returns the defaultGson.static com.google.gson.GsonBuildergetDefaultGsonBuilder()Returns the defaultGsonBuilder.static voidregisterTypeAdapters(com.google.gson.GsonBuilder builder)Registers the NodeGraph classes with aGsonBuilder.static com.google.gson.JsonElementserializeNodeConnection(NodeConnection connection)Used for serializing a singleNodeConnectionto aJsonElementstatic com.google.gson.JsonElementserializeNodeConnections(java.util.Collection<NodeConnection> nodeConnections)static com.google.gson.JsonElementserializeNodeVariable(NodeVariable<?> variable)Used for serializing a singleNodeVariableto aJsonElementstatic com.google.gson.JsonElementserializeNodeVariables(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 givenNodeGraphusing json serialization/deserialization -
deepCopy
Creates a deep copy of the givenNodeusing json serialization/deserialization -
serializeNodeConnections
public static com.google.gson.JsonElement serializeNodeConnections(java.util.Collection<NodeConnection> nodeConnections)- Parameters:
nodeConnections- theCollectionofNodeConnections to serialize- Returns:
- a
JsonElementrepresenting the list ofNodeConnections
-
deserializeNodeConnections
public static void deserializeNodeConnections(com.google.gson.JsonElement jsonElement, NodeGraph dstGraph)- Parameters:
jsonElement- theJsonElementto read theCollectionofNodeConnections fromdstGraph- the destinationNodeGraph, where the connections will be added
-
serializeNodeConnection
Used for serializing a singleNodeConnectionto aJsonElement- Parameters:
connection- theNodeConnectionto serialize- Returns:
- a
JsonElementrepresenting theNodeConnection
-
deserializeNodeConnection
public static NodeConnection deserializeNodeConnection(com.google.gson.JsonElement jsonElement, NodeGraph dstGraph)Used for de-serializing a singleNodeConnectionfrom 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- theJsonElementto de-serialize theNodeConnectionfromdstGraph- the destinationNodeGraph- Returns:
- the
NodeConnection
-
serializeNodeVariables
public static com.google.gson.JsonElement serializeNodeVariables(java.util.Collection<NodeVariable<?>> variables)- Parameters:
variables- theCollectionofNodeVariables to serialize- Returns:
- a
JsonElementrepresenting theCollectionofNodeVariable
-
deserializeNodeVariables
public static void deserializeNodeVariables(java.util.Collection<NodeVariable<?>> variables, com.google.gson.JsonElement jsonElement)- Parameters:
variables- theCollectionofNodeVariables to deserialize into, MUST contain all of theNodeVariables required already.jsonElement- the element to de-serialize the nodes from
-
serializeNodeVariable
Used for serializing a singleNodeVariableto aJsonElement- Parameters:
variable- theNodeVariables to serialize- Returns:
- a
JsonElementrepresenting theNodeVariable
-
deserializeNodeVariable
public static void deserializeNodeVariable(NodeVariable<?> variable, com.google.gson.JsonElement jsonElement)Used for de-serializing a singleNodeVariablefrom aJsonElement- Parameters:
variable- theNodeVariables to deserialize intojsonElement- the element to de-serialize the nodes from
-