summaryrefslogtreecommitdiffstats
path: root/src/main/java/org/onap/sdc/dcae/composition/restmodels/ruleeditor/ActionDeserializer.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/org/onap/sdc/dcae/composition/restmodels/ruleeditor/ActionDeserializer.java')
-rw-r--r--src/main/java/org/onap/sdc/dcae/composition/restmodels/ruleeditor/ActionDeserializer.java34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/main/java/org/onap/sdc/dcae/composition/restmodels/ruleeditor/ActionDeserializer.java b/src/main/java/org/onap/sdc/dcae/composition/restmodels/ruleeditor/ActionDeserializer.java
new file mode 100644
index 0000000..84884ee
--- /dev/null
+++ b/src/main/java/org/onap/sdc/dcae/composition/restmodels/ruleeditor/ActionDeserializer.java
@@ -0,0 +1,34 @@
+package org.onap.sdc.dcae.composition.restmodels.ruleeditor;
+
+import com.google.gson.*;
+import java.lang.reflect.Type;
+
+public class ActionDeserializer implements JsonDeserializer<BaseAction> {
+
+ @Override
+ public BaseAction deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
+ String action;
+ try {
+ action = json.getAsJsonObject().get("actionType").getAsString();
+ } catch (RuntimeException e) {
+ throw new JsonParseException("Missing information : action type");
+ }
+ ActionTypeEnum actionTypeEnum = ActionTypeEnum.getTypeByName(action);
+ if (null == actionTypeEnum)
+ throw new JsonParseException("Undefined action type: " + action);
+ Type clazz = getActionClassByActionTypeEnum(actionTypeEnum);
+ return new Gson().fromJson(json, clazz);
+ }
+
+ private Type getActionClassByActionTypeEnum(ActionTypeEnum actionTypeEnum) {
+ switch (actionTypeEnum) {
+ case MAP:
+ return MapAction.class;
+ case DATE_FORMATTER:
+ return DateFormatterAction.class;
+ default:
+ return BaseAction.class;
+ }
+ }
+
+}