mirror of https://github.com/apache/cloudstack.git
bug 14313: add map type adapter to ApiGsonBuilder as some API response classes are using Map<String, String>
This commit is contained in:
parent
4233cd7aba
commit
93151a701c
|
|
@ -18,6 +18,8 @@
|
|||
|
||||
package com.cloud.api;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import com.google.gson.GsonBuilder;
|
||||
|
||||
public class ApiGsonHelper {
|
||||
|
|
@ -27,6 +29,7 @@ public class ApiGsonHelper {
|
|||
s_gBuilder.setVersion(1.3);
|
||||
s_gBuilder.registerTypeAdapter(ResponseObject.class, new ResponseObjectTypeAdapter());
|
||||
s_gBuilder.registerTypeAdapter(IdentityProxy.class, new IdentityTypeAdapter());
|
||||
s_gBuilder.registerTypeAdapter(Map.class, new StringMapTypeAdapter());
|
||||
}
|
||||
|
||||
public static GsonBuilder getBuilder() {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,30 @@
|
|||
package com.cloud.api;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import com.google.gson.JsonDeserializationContext;
|
||||
import com.google.gson.JsonDeserializer;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParseException;
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
public class StringMapTypeAdapter implements JsonDeserializer<Map> {
|
||||
@Override
|
||||
|
||||
public Map deserialize(JsonElement src, Type srcType,
|
||||
JsonDeserializationContext context) throws JsonParseException {
|
||||
|
||||
Map<String, String> obj = new HashMap<String, String>();
|
||||
JsonObject json = src.getAsJsonObject();
|
||||
|
||||
for(Entry<String, JsonElement> entry : json.entrySet()) {
|
||||
obj.put(entry.getKey(), entry.getValue().getAsString());
|
||||
}
|
||||
|
||||
return obj;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue