diff options
author | Manuel Carrasco Moñino <manuel.carrasco.m@gmail.com> | 2014-02-18 11:47:28 +0100 |
---|---|---|
committer | Manuel Carrasco Moñino <manuel.carrasco.m@gmail.com> | 2014-02-18 11:47:28 +0100 |
commit | 859a65dac1dc46c16f558f083d9640276cd7d1ad (patch) | |
tree | 8bfbb11f30b02cf55b9a7f9436579af8619e2439 | |
parent | 28b68df025e52a4c39a9e55b1e0196cdbb057045 (diff) | |
download | gwtquery-859a65dac1dc46c16f558f083d9640276cd7d1ad.tar.gz gwtquery-859a65dac1dc46c16f558f083d9640276cd7d1ad.zip |
Fix bad parsing null in jre
-rw-r--r-- | gwtquery-core/src/main/java/com/google/gwt/query/vm/JsonFactoryJre.java | 14 | ||||
-rw-r--r-- | gwtquery-core/src/test/java/com/google/gwt/query/client/dbinding/DataBindingTestJre.java | 4 |
2 files changed, 11 insertions, 7 deletions
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()); |