import com.google.gson.*
import java.lang.reflect.Type
class GsonUtils {
static Gson getGson(){
Gson gson=new GsonBuilder().registerTypeAdapter(HashMap.class, new JsonDeserializer<HashMap>() {
public HashMap deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
throws JsonParseException{
def resultMap=[:]
def jsonObject = json.getAsJsonObject()
Set<Map.Entry<String, JsonElement>> entrySet = jsonObject.entrySet()
for (Map.Entry<String, JsonElement> entry : entrySet) {
resultMap[entry.getKey()] = entry.getValue()
}
return resultMap
}
}).create();
return gson
}
}
Gson反射hashmap时数字转变为double的解决方法
原文:http://my.oschina.net/sphl520/blog/411236