com.tencentcloudapi.common.CommonRequest Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of tencentcloud-sdk-java-common Show documentation
Show all versions of tencentcloud-sdk-java-common Show documentation
Tencent Cloud Open API SDK for Java
The newest version!
package com.tencentcloudapi.common;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.reflect.TypeToken;
import java.lang.reflect.Type;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public final class CommonRequest extends AbstractModel {
private static final Gson gson = new GsonBuilder().create();
private static final Type typeToken = new TypeToken>() {
}.getType();
public CommonRequest(String jsonReq) {
HashMap body = gson.fromJson(jsonReq, typeToken);
for (Map.Entry entry : body.entrySet()) {
set(entry.getKey(), entry.getValue());
}
}
@Override
protected void toMap(HashMap map, String prefix) {
toMapFromObject(map, prefix, any());
}
private void toMapFromObject(HashMap map, String prefix, Object layer) {
if (layer == null)
return;
if (layer instanceof List) {
if (!prefix.isEmpty()) {
prefix += ".";
}
int i = 0;
for (Object entry : (List) layer) {
toMapFromObject(map, prefix + i, entry);
i++;
}
} else if (layer instanceof Map) {
if (!prefix.isEmpty()) {
prefix += ".";
}
for (Map.Entry entry : ((Map) layer).entrySet()) {
String key = entry.getKey();
Object val = entry.getValue();
toMapFromObject(map, prefix + key, val);
}
} else {
map.put(prefix, layer.toString());
}
}
}