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 Details

    • JSONHelper

      public JSONHelper()
  • Method Details

    • getDefaultGson

      public static com.google.gson.Gson getDefaultGson()
      Returns the default Gson.
      Returns:
      the default Gson.
    • getDefaultGsonBuilder

      public static com.google.gson.GsonBuilder getDefaultGsonBuilder()
      Returns the default GsonBuilder.
      Returns:
      the default GsonBuilder.
    • registerTypeAdapters

      public static void registerTypeAdapters​(com.google.gson.GsonBuilder builder)
      Registers the NodeGraph classes with a GsonBuilder.
      Parameters:
      builder - the GsonBuilder.
    • deepCopy

      public static NodeGraph deepCopy​(NodeGraph graph)
      Creates a deep copy of the given NodeGraph using json serialization/deserialization
      Parameters:
      graph - the NodeGraph to copy
      Returns:
      the NodeGraph copy
    • deepCopy

      public static Node deepCopy​(Node source)
      Creates a deep copy of the given Node using json serialization/deserialization
      Parameters:
      source - the NodeGraph to copy
      Returns:
      the NodeGraph copy
    • serializeNodeConnections

      public static com.google.gson.JsonElement serializeNodeConnections​(java.util.Collection<NodeConnection> nodeConnections)
      Used for serializing a Collection of NodeConnections to a JsonElement
      Parameters:
      nodeConnections - the Collection of NodeConnections to serialize
      Returns:
      a JsonElement representing the list of NodeConnections
    • deserializeNodeConnections

      public static void deserializeNodeConnections​(com.google.gson.JsonElement jsonElement, NodeGraph dstGraph)
      Used for serializing a Collection of NodeConnections from a JsonElement
      Parameters:
      jsonElement - the JsonElement to read the Collection of NodeConnections from
      dstGraph - the destination NodeGraph, where the connections will be added
    • serializeNodeConnection

      public static com.google.gson.JsonElement serializeNodeConnection​(NodeConnection connection)
      Used for serializing a single NodeConnection to a JsonElement
      Parameters:
      connection - the NodeConnection to serialize
      Returns:
      a JsonElement representing the NodeConnection
    • deserializeNodeConnection

      public static NodeConnection deserializeNodeConnection​(com.google.gson.JsonElement jsonElement, NodeGraph dstGraph)
      Used for de-serializing a single NodeConnection from a JsonElement. This method only performs the deserialization and doesn't add the connection to the graph, that is handled by deserializeNodeConnections(com.google.gson.JsonElement, com.marginallyclever.nodegraphcore.NodeGraph)
      Parameters:
      jsonElement - the JsonElement to de-serialize the NodeConnection from
      dstGraph - the destination NodeGraph
      Returns:
      the NodeConnection
    • serializeNodeVariables

      public static com.google.gson.JsonElement serializeNodeVariables​(java.util.Collection<NodeVariable<?>> variables)
      Used for serializing a Collection of NodeVariables to a JsonElement
      Parameters:
      variables - the Collection of NodeVariables to serialize
      Returns:
      a JsonElement representing the Collection of NodeVariable
    • deserializeNodeVariables

      public static void deserializeNodeVariables​(java.util.Collection<NodeVariable<?>> variables, com.google.gson.JsonElement jsonElement)
      Used for de-serializing a Collection of NodeVariables to a JsonElement
      Parameters:
      variables - the Collection of NodeVariables to deserialize into, MUST contain all of the NodeVariables required already.
      jsonElement - the element to de-serialize the nodes from
    • serializeNodeVariable

      public static com.google.gson.JsonElement serializeNodeVariable​(NodeVariable<?> variable)
      Used for serializing a single NodeVariable to a JsonElement
      Parameters:
      variable - the NodeVariables to serialize
      Returns:
      a JsonElement representing the NodeVariable
    • deserializeNodeVariable

      public static void deserializeNodeVariable​(NodeVariable<?> variable, com.google.gson.JsonElement jsonElement)
      Used for de-serializing a single NodeVariable from a JsonElement
      Parameters:
      variable - the NodeVariables to deserialize into
      jsonElement - the element to de-serialize the nodes from