Class JsonSerialization

java.lang.Object
io.lionweb.lioncore.java.serialization.AbstractSerialization
io.lionweb.lioncore.java.serialization.JsonSerialization

public class JsonSerialization extends AbstractSerialization
This class is responsible for deserializing models.

The deserialization of each node _requires_ the deserializer to be able to resolve the Concept used. If this requirement is not satisfied the deserialization will fail. The actual class implementing Node being instantiated will depend on the configuration. Specific classes for specific Concepts can be registered, and the usage of DynamicNode for all others can be enabled.

Note that by default JsonSerialization will require specific Node subclasses to be specified. For example, it will need to know that the concept with id 'foo-library' can be deserialized to instances of the class Library. If you want serialization to instantiate DynamicNodes for concepts for which you do not have a corresponding Node subclass, then you need to enable that behavior explicitly by calling getNodeInstantiator().enableDynamicNodes().

  • Method Details

    • saveLanguageToFile

      public static void saveLanguageToFile(Language language, File file) throws IOException
      Throws:
      IOException
    • loadLanguage

      public Language loadLanguage(File file) throws IOException
      Load a single Language from a file. If the file contains more than one language an exception is thrown.
      Throws:
      IOException
    • loadLanguage

      public Language loadLanguage(InputStream inputStream)
      Load a single Language from an InputStream. If the InputStream contains more than one language an exception is thrown.
    • loadLanguage

      public Language loadLanguage(String json)
      Load a single Language from a string. If the file contains more than one language an exception is thrown.
    • serializeTreeToJsonElement

      public com.google.gson.JsonElement serializeTreeToJsonElement(ClassifierInstance<?> classifierInstance)
    • serializeTreesToJsonElement

      public com.google.gson.JsonElement serializeTreesToJsonElement(ClassifierInstance<?>... roots)
    • serializeNodesToJsonElement

      public com.google.gson.JsonElement serializeNodesToJsonElement(List<ClassifierInstance<?>> classifierInstances)
    • serializeNodesToJsonElement

      public com.google.gson.JsonElement serializeNodesToJsonElement(ClassifierInstance<?>... classifierInstances)
    • serializeTreeToJsonString

      public String serializeTreeToJsonString(ClassifierInstance<?> classifierInstance)
    • serializeTreesToJsonString

      public String serializeTreesToJsonString(ClassifierInstance<?>... classifierInstances)
    • serializeNodesToJsonString

      public String serializeNodesToJsonString(List<ClassifierInstance<?>> classifierInstances)
    • serializeNodesToJsonString

      public String serializeNodesToJsonString(ClassifierInstance<?>... classifierInstances)
    • deserializeToNodes

      public List<Node> deserializeToNodes(File file) throws FileNotFoundException
      Throws:
      FileNotFoundException
    • deserializeToNodes

      public List<Node> deserializeToNodes(com.google.gson.JsonElement jsonElement)
    • deserializeToClassifierInstances

      public List<ClassifierInstance<?>> deserializeToClassifierInstances(com.google.gson.JsonElement jsonElement)
    • deserializeToNodes

      public List<Node> deserializeToNodes(URL url) throws IOException
      Throws:
      IOException
    • deserializeToNodes

      public List<Node> deserializeToNodes(String json)
    • deserializeToNodes

      public List<Node> deserializeToNodes(InputStream inputStream)