com.adzerk.sdk.model.DecisionResponse Maven / Gradle / Ivy
package com.adzerk.sdk.model;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.adzerk.sdk.generated.model.Decision;
import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.internal.LinkedTreeMap;
import com.google.gson.reflect.TypeToken;
import io.swagger.annotations.ApiModelProperty;
public class DecisionResponse extends com.adzerk.sdk.generated.model.DecisionResponse {
private static final long serialVersionUID = 1;
@javax.annotation.Nullable
@ApiModelProperty(value = "")
public Map> getDecisions() {
Gson gson = new Gson();
HashMap> result = new HashMap>();
Type mapType = new TypeToken>(){}.getType();
Type decisionType = new TypeToken(){}.getType();
Type decisionListType = new TypeToken>(){}.getType();
JsonObject mapJsonObject = gson.toJsonTree(super.getDecisions()).getAsJsonObject();
Map map = gson.fromJson(mapJsonObject, mapType);
for(String key : map.keySet()) {
JsonElement element = gson.toJsonTree(map.get(key));
if (element.isJsonObject()) {
JsonObject obj = element.getAsJsonObject();
Decision parsed = gson.fromJson(obj, decisionType);
result.put(key, Arrays.asList(parsed));
} else {
JsonArray obj = element.getAsJsonArray();
ArrayList parsed = gson.fromJson(obj, decisionListType);
result.put(key, parsed);
}
}
return result;
}
@javax.annotation.Nullable
@ApiModelProperty(value = "")
public Map getExplain() {
LinkedTreeMap, ?> explanation = (LinkedTreeMap, ?>) super.getExplain();
if (explanation == null) { return null; }
return (Map) explanation;
}
}