From: Manuel Carrasco MoƱino Date: Tue, 18 Feb 2014 10:47:28 +0000 (+0100) Subject: Fix bad parsing null in jre X-Git-Tag: gwtquery-project-1.4.3~41^2~3 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=859a65dac1dc46c16f558f083d9640276cd7d1ad;p=gwtquery.git Fix bad parsing null in jre --- diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/vm/JsonFactoryJre.java b/gwtquery-core/src/main/java/com/google/gwt/query/vm/JsonFactoryJre.java index 76deabb2..97243244 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/vm/JsonFactoryJre.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/vm/JsonFactoryJre.java @@ -66,8 +66,6 @@ public class JsonFactoryJre implements JsonFactory { ret = jsonArrayToList(obj.getJSONArray(attr), ctype, clz.isArray()); } else if (clz.equals(Date.class)) { ret = new Date(obj != null ? obj.getLong(attr): arr.getLong(idx)); - } else if (clz.equals(String.class)) { - ret = String.valueOf(obj != null ? obj.get(attr) : arr.get(idx)); } else if (clz.equals(Boolean.class) || clz.isPrimitive() && clz == Boolean.TYPE) { try { ret = obj != null ? obj.getBoolean(attr): arr.getBoolean(idx); @@ -97,15 +95,19 @@ public class JsonFactoryJre implements JsonFactory { } } else { ret = obj != null ? obj.get(attr): arr.get(idx); - if (ret instanceof JSONObject) { + if (ret == JSONObject.NULL ) { + // org.json returns an Null object instead of null when parsing. + ret = null; + } else if (clz.equals(String.class)) { + ret = String.valueOf(ret); + } else if (ret instanceof JSONObject) { if (clz == Object.class) { ret = jsonFactory.createBinder((JSONObject)ret); } else if (IsProperties.class.isAssignableFrom(clz) && !clz.isAssignableFrom(ret.getClass())) { ret = jsonFactory.create(clz, (JSONObject)ret); } - } - // Javascript always returns a double - if (ret instanceof Number) { + } else if (ret instanceof Number) { + // Javascript always returns a double ret = Double.valueOf(((Number) ret).doubleValue()); } } diff --git a/gwtquery-core/src/test/java/com/google/gwt/query/client/dbinding/DataBindingTestJre.java b/gwtquery-core/src/test/java/com/google/gwt/query/client/dbinding/DataBindingTestJre.java index ac648fc1..874fb6ef 100644 --- a/gwtquery-core/src/test/java/com/google/gwt/query/client/dbinding/DataBindingTestJre.java +++ b/gwtquery-core/src/test/java/com/google/gwt/query/client/dbinding/DataBindingTestJre.java @@ -62,16 +62,18 @@ public class DataBindingTestJre extends GWTTestCase { void y(String s); Function getF(); void setF(Function f); + String getN(); } boolean functionRun = false; public void testJsonBuilder() { - String json = "{M:0, a:1, b:{a:2,b:{a:3}},u:url, d:'2','t':['hola','adios'], 'z': true, 'items':[{'date':100}]}"; + String json = "{n: null, M:0, a:1, b:{a:2,b:{a:3}},u:url, d:'2','t':['hola','adios'], 'z': true, 'items':[{'date':100}]}"; JsonExample c = GQ.create(JsonExample.class); assertEquals(0, c.getA()); c.parse(json, true); + assertNull(c.getN()); assertEquals(0, c.getM()); assertEquals(1, c.getA()); assertNotNull(c.getB());