Gson反射hashmap时数字转变为double的解决方法

时间:2015-05-06 13:26:23   收藏:0   阅读:322
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
    }
}


原文:http://my.oschina.net/sphl520/blog/411236

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!