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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiondeserialize
(com.google.gson.JsonElement json, Type typeOfT, com.google.gson.JsonDeserializationContext context) Deserializes JSON into aScenarioStepComponent
object.com.google.gson.JsonElement
serialize
(ScenarioStepComponent src, Type typeOfSrc, com.google.gson.JsonSerializationContext context) Serializes aScenarioStepComponent
object into its JSON representation.
-
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 aScenarioStepComponent
object. This method checks for the presence of the "substeps" field in the JSON object to determine whether to instantiate aScenarioStepComposite
orScenarioStepLeaf
.- Specified by:
deserialize
in interfacecom.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 aScenarioStepComponent
object into its JSON representation. This method checks the type of theScenarioStepComponent
instance and serializes it as either aScenarioStepComposite
orScenarioStepLeaf
.- Specified by:
serialize
in interfacecom.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.
-