Implementing gson in android client templates

This commit is contained in:
Andrew B
2015-05-06 22:54:25 -07:00
parent 902c56f09b
commit 01b7385a5e
7 changed files with 137 additions and 22 deletions

View File

@@ -155,8 +155,7 @@ public class ApiInvoker {
public static Object deserialize(String json, String containerType, Class cls) throws ApiException {
try{
if("list".equalsIgnoreCase(containerType) || "array".equalsIgnoreCase(containerType)) {
List response = (List<?>) JsonUtil.getGson().fromJson(json, cls);
return response;
return JsonUtil.deserializeToList(json, cls);
}
else if(String.class.equals(cls)) {
if(json != null && json.startsWith("\"") && json.endsWith("\"") && json.length() > 1)
@@ -165,7 +164,7 @@ public class ApiInvoker {
return json;
}
else {
return JsonUtil.getGson().fromJson(json, cls);
return JsonUtil.deserializeToObject(json, cls);
}
}
catch (JsonParseException e) {
@@ -176,7 +175,7 @@ public class ApiInvoker {
public static String serialize(Object obj) throws ApiException {
try {
if (obj != null)
return JsonUtil.getGson().toJson(obj);
return JsonUtil.serialize(obj);
else
return null;
}