Index: forgon-tools/src/main/java/com/forgon/tools/json/JSONUtil.java =================================================================== diff -u -r15594 -r15911 --- forgon-tools/src/main/java/com/forgon/tools/json/JSONUtil.java (.../JSONUtil.java) (revision 15594) +++ forgon-tools/src/main/java/com/forgon/tools/json/JSONUtil.java (.../JSONUtil.java) (revision 15911) @@ -38,6 +38,7 @@ import com.forgon.tools.date.DateTools; import com.forgon.tools.string.StringTools; import com.google.gson.Gson; +import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.google.gson.JsonPrimitive; @@ -383,28 +384,28 @@ public static String optString(JsonObject obj,String key, String defValue){ - JsonPrimitive jsonPrimitive = obj.getAsJsonPrimitive(key); - if(jsonPrimitive == null){ + JsonElement jsonElement = obj.get(key); + if(jsonElement.isJsonNull()){ return defValue; } - return jsonPrimitive.getAsString(); + return jsonElement.getAsString(); } public static Long optLong(JsonObject obj,String key, Long defValue){ - JsonPrimitive jsonPrimitive = obj.getAsJsonPrimitive(key); - if(jsonPrimitive == null){ + JsonElement jsonElement = obj.get(key); + if(jsonElement.isJsonNull()){ return defValue; } - return jsonPrimitive.getAsLong(); + return jsonElement.getAsLong(); } public static int optInt(JsonObject obj,String key, int defValue){ - JsonPrimitive jsonPrimitive = obj.getAsJsonPrimitive(key); - if(jsonPrimitive == null){ + JsonElement jsonElement = obj.get(key); + if(jsonElement.isJsonNull()){ return defValue; } - return jsonPrimitive.getAsInt(); + return jsonElement.getAsInt(); } }