blob: 84884ee6ed6dc347fcac7371056ec5097810a34b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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;
}
}
}
|