chemistry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From f...@apache.org
Subject svn commit: r1442883 - /chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/json/JSONObject.java
Date Wed, 06 Feb 2013 10:07:26 GMT
Author: fmui
Date: Wed Feb  6 10:07:26 2013
New Revision: 1442883

URL: http://svn.apache.org/viewvc?rev=1442883&view=rev
Log:
better JSON null key handling

Modified:
    chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/json/JSONObject.java

Modified: chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/json/JSONObject.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/json/JSONObject.java?rev=1442883&r1=1442882&r2=1442883&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/json/JSONObject.java
(original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/json/JSONObject.java
Wed Feb  6 10:07:26 2013
@@ -33,7 +33,17 @@ import java.util.Map;
  * @author FangYidong<fangyidong@yahoo.com.cn>
  */
 public class JSONObject extends HashMap<String, Object> implements Map<String, Object>,
JSONAware, JSONStreamAware {
-    private static final long serialVersionUID = -503443796854799292L;
+
+    private static final long serialVersionUID = 1;
+
+    @Override
+    public Object put(String key, Object value) {
+        if (key == null) {
+            throw new NullPointerException("JSON key must not be null!");
+        }
+
+        return super.put(key, value);
+    }
 
     /**
      * Encode a map into JSON text and write it to out. If this map is also a
@@ -62,7 +72,11 @@ public class JSONObject extends HashMap<
             }
 
             out.write('\"');
-            out.write(escape(entry.getKey()));
+            if (entry.getKey() == null) {
+                out.write("null");
+            } else {
+                out.write(escape(entry.getKey()));
+            }
             out.write('\"');
             out.write(':');
             JSONValue.writeJSONString(entry.getValue(), out);



Mime
View raw message