From 859a65dac1dc46c16f558f083d9640276cd7d1ad Mon Sep 17 00:00:00 2001 From: =?utf8?q?Manuel=20Carrasco=20Mo=C3=B1ino?= Date: Tue, 18 Feb 2014 11:47:28 +0100 Subject: [PATCH] Fix bad parsing null in jre --- .../com/google/gwt/query/vm/JsonFactoryJre.java | 14 ++++++++------ .../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()); -- 2.39.5