wink-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From b...@apache.org
Subject svn commit: r1030612 - in /incubator/wink/trunk/wink-json4j/src: main/java/org/apache/wink/json4j/JSONObject.java main/java/org/apache/wink/json4j/internal/BeanSerializer.java test/java/org/apache/wink/json4j/tests/JSONObjectTest.java
Date Wed, 03 Nov 2010 18:56:36 GMT
Author: bluk
Date: Wed Nov  3 18:56:35 2010
New Revision: 1030612

URL: http://svn.apache.org/viewvc?rev=1030612&view=rev
Log:
wink-json fixes

Issue with NULL entries fixed

Fix ability to use JSONArray with
array types.

Modified:
    incubator/wink/trunk/wink-json4j/src/main/java/org/apache/wink/json4j/JSONObject.java
    incubator/wink/trunk/wink-json4j/src/main/java/org/apache/wink/json4j/internal/BeanSerializer.java
    incubator/wink/trunk/wink-json4j/src/test/java/org/apache/wink/json4j/tests/JSONObjectTest.java

Modified: incubator/wink/trunk/wink-json4j/src/main/java/org/apache/wink/json4j/JSONObject.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-json4j/src/main/java/org/apache/wink/json4j/JSONObject.java?rev=1030612&r1=1030611&r2=1030612&view=diff
==============================================================================
--- incubator/wink/trunk/wink-json4j/src/main/java/org/apache/wink/json4j/JSONObject.java
(original)
+++ incubator/wink/trunk/wink-json4j/src/main/java/org/apache/wink/json4j/JSONObject.java
Wed Nov  3 18:56:35 2010
@@ -1365,7 +1365,7 @@ public class JSONObject extends HashMap 
      * @return true if the key is not in the map or if the value referenced by the key is
null.
      */
     public boolean isNull(String key) {
-        if (this.opt(key) == null) {
+        if ( (this.opt(key) == null) || (NULL == this.opt(key)) ) {
             return true;
         }
         return false;

Modified: incubator/wink/trunk/wink-json4j/src/main/java/org/apache/wink/json4j/internal/BeanSerializer.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-json4j/src/main/java/org/apache/wink/json4j/internal/BeanSerializer.java?rev=1030612&r1=1030611&r2=1030612&view=diff
==============================================================================
--- incubator/wink/trunk/wink-json4j/src/main/java/org/apache/wink/json4j/internal/BeanSerializer.java
(original)
+++ incubator/wink/trunk/wink-json4j/src/main/java/org/apache/wink/json4j/internal/BeanSerializer.java
Wed Nov  3 18:56:35 2010
@@ -67,7 +67,10 @@ public class BeanSerializer {
                 ja = new JSONObject((Map)obj);
             } else if (Collection.class.isAssignableFrom(clazz)) {
                 ja = new JSONArray((Collection)obj);
-            } else {
+            } else if (clazz.isArray()) {
+                ja = new JSONArray((Object[])obj);
+            } 
+            else {
                 //TODO:  Bean introspection time.
                 ja = introspectBean(obj,includeSuperclass, new ArrayList());
             }

Modified: incubator/wink/trunk/wink-json4j/src/test/java/org/apache/wink/json4j/tests/JSONObjectTest.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-json4j/src/test/java/org/apache/wink/json4j/tests/JSONObjectTest.java?rev=1030612&r1=1030611&r2=1030612&view=diff
==============================================================================
--- incubator/wink/trunk/wink-json4j/src/test/java/org/apache/wink/json4j/tests/JSONObjectTest.java
(original)
+++ incubator/wink/trunk/wink-json4j/src/test/java/org/apache/wink/json4j/tests/JSONObjectTest.java
Wed Nov  3 18:56:35 2010
@@ -23,6 +23,8 @@ import junit.framework.TestCase;
 import junit.framework.TestSuite;
 import java.io.*;
 import java.util.Iterator;
+import java.util.LinkedHashMap;
+import java.util.Map;
 import java.util.Set;
 import java.util.HashMap;
 import java.util.Date;
@@ -126,22 +128,29 @@ public class JSONObjectTest extends Test
      */
     public void test_newFromMap() {
         JSONObject jObject = null;
+        JSONArray jArr = null;
         Exception ex = null;
         HashMap map = new HashMap();
         map.put("string", "This is a string");
         map.put("null", null);
         map.put("integer", new Integer(1));
         map.put("bool", new Boolean(true));
+        map.put("strArr", new String[]{"first", "second", "third"});
 
         // Load a JSON object from a map with JSONable values.
         try {
             jObject = new JSONObject(map);
+            jArr = (JSONArray)jObject.get("strArr");
         } catch (Exception ex1) {
             ex = ex1;
             ex.printStackTrace();
         }
         assertTrue(jObject != null);
-        assertTrue(jObject.length() == 4);
+        assertTrue(jObject.length() == 5);
+        assertTrue("first".equals((String)jArr.get(0)));
+        assertTrue("second".equals((String)jArr.get(1)));
+        assertTrue("third".equals((String)jArr.get(2)));
+
         assertTrue(ex == null);
     }
 
@@ -1501,6 +1510,22 @@ public class JSONObjectTest extends Test
         assertTrue(ex1 != null);
     }
 
+  
+    public void testIsNull() {
+        Map jsonMap = new LinkedHashMap(1);
+        jsonMap.put("key1", null);
+        jsonMap.put("key2", JSONObject.NULL);
+        jsonMap.put("key3", "NOT NULL");
+        
+        
+        JSONObject json = new JSONObject(jsonMap);
+        
+        assertTrue(json.isNull("key1"));
+        assertTrue(json.isNull("key2"));
+        assertFalse(json.isNull("key3"));
+    }
+    
+
 
     /*****************************************************************/
     /* The following tests checks basic 'java beans' convert to JSON */



Mime
View raw message