Class TypeFromNodeAdaptor

java.lang.Object
Services.Dependencies.TypeFromNodeAdaptor
All Implemented Interfaces:
com.google.gson.JsonDeserializer<MyNode>

public class TypeFromNodeAdaptor extends Object implements com.google.gson.JsonDeserializer<MyNode>
Custom Gson deserializer for MyNode objects.

This deserializer handles polymorphic deserialization based on the presence of specific fields in the JSON. If the JSON object contains the field "ignorefirstLine", it is deserialized as a CSVNode; otherwise, it is deserialized as a regular MyNode.

This is useful for converting JSON representations of nodes in a dependency graph where some nodes may represent CSV data.

  • Constructor Details

    • TypeFromNodeAdaptor

      public TypeFromNodeAdaptor()
  • Method Details

    • deserialize

      public MyNode deserialize(com.google.gson.JsonElement jsonElement, Type type, com.google.gson.JsonDeserializationContext jsonDeserializationContext) throws com.google.gson.JsonParseException
      Deserializes a JSON element into either a MyNode or CSVNode depending on the presence of the "ignorefirstLine" field.
      Specified by:
      deserialize in interface com.google.gson.JsonDeserializer<MyNode>
      Parameters:
      jsonElement - the JSON element to deserialize
      type - the type of the object to deserialize to (should be MyNode)
      jsonDeserializationContext - the Gson context for deserialization
      Returns:
      the deserialized MyNode or CSVNode instance
      Throws:
      com.google.gson.JsonParseException - if deserialization fails