Class ScenarioStepComponentAdapter

java.lang.Object
pl.put.poznan.qualitychecker.logic.ScenarioStepComponentAdapter
All Implemented Interfaces:
com.google.gson.JsonDeserializer<ScenarioStepComponent>, com.google.gson.JsonSerializer<ScenarioStepComponent>

public class ScenarioStepComponentAdapter extends Object implements com.google.gson.JsonDeserializer<ScenarioStepComponent>, com.google.gson.JsonSerializer<ScenarioStepComponent>
Custom Gson adapter for serializing and deserializing ScenarioStepComponent objects. This class implements both JsonDeserializer and JsonSerializer to handle the conversion between JSON and ScenarioStepComponent subclasses.
  • Constructor Details

    • ScenarioStepComponentAdapter

      public ScenarioStepComponentAdapter()
  • Method Details

    • deserialize

      public ScenarioStepComponent deserialize(com.google.gson.JsonElement json, Type typeOfT, com.google.gson.JsonDeserializationContext context) throws com.google.gson.JsonParseException
      Deserializes JSON into a ScenarioStepComponent object. This method checks for the presence of the "substeps" field in the JSON object to determine whether to instantiate a ScenarioStepComposite or ScenarioStepLeaf.
      Specified by:
      deserialize in interface com.google.gson.JsonDeserializer<ScenarioStepComponent>
      Parameters:
      json - The JSON data being deserialized.
      typeOfT - The type of the Object to deserialize to.
      context - The deserialization context.
      Returns:
      The deserialized ScenarioStepComponent object.
      Throws:
      com.google.gson.JsonParseException - If JSON is not in the expected format.
    • serialize

      public com.google.gson.JsonElement serialize(ScenarioStepComponent src, Type typeOfSrc, com.google.gson.JsonSerializationContext context)
      Serializes a ScenarioStepComponent object into its JSON representation. This method checks the type of the ScenarioStepComponent instance and serializes it as either a ScenarioStepComposite or ScenarioStepLeaf.
      Specified by:
      serialize in interface com.google.gson.JsonSerializer<ScenarioStepComponent>
      Parameters:
      src - The source object to serialize.
      typeOfSrc - The actual type of the source object.
      context - The serialization context.
      Returns:
      The serialized JSON element.