incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jus...@apache.org
Subject svn commit: r1497518 - in /sling/trunk/bundles/commons/json/src: main/java/org/apache/sling/commons/json/JSONObject.java test/java/org/apache/sling/commons/json/JSONObjectTest.java
Date Thu, 27 Jun 2013 19:29:00 GMT
Author: justin
Date: Thu Jun 27 19:28:59 2013
New Revision: 1497518

URL: http://svn.apache.org/r1497518
Log:
SLING-2937 - using Long.valueOf() in getLong() to ensure correct parsing

Modified:
    sling/trunk/bundles/commons/json/src/main/java/org/apache/sling/commons/json/JSONObject.java
    sling/trunk/bundles/commons/json/src/test/java/org/apache/sling/commons/json/JSONObjectTest.java

Modified: sling/trunk/bundles/commons/json/src/main/java/org/apache/sling/commons/json/JSONObject.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/commons/json/src/main/java/org/apache/sling/commons/json/JSONObject.java?rev=1497518&r1=1497517&r2=1497518&view=diff
==============================================================================
--- sling/trunk/bundles/commons/json/src/main/java/org/apache/sling/commons/json/JSONObject.java
(original)
+++ sling/trunk/bundles/commons/json/src/main/java/org/apache/sling/commons/json/JSONObject.java
Thu Jun 27 19:28:59 2013
@@ -484,7 +484,8 @@ public class JSONObject {
     public long getLong(String key) throws JSONException {
         Object o = get(key);
         return o instanceof Number ?
-                ((Number)o).longValue() : (long)getDouble(key);
+                ((Number)o).longValue() :
+                Long.valueOf((String)o).longValue();
     }
 
 

Modified: sling/trunk/bundles/commons/json/src/test/java/org/apache/sling/commons/json/JSONObjectTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/commons/json/src/test/java/org/apache/sling/commons/json/JSONObjectTest.java?rev=1497518&r1=1497517&r2=1497518&view=diff
==============================================================================
--- sling/trunk/bundles/commons/json/src/test/java/org/apache/sling/commons/json/JSONObjectTest.java
(original)
+++ sling/trunk/bundles/commons/json/src/test/java/org/apache/sling/commons/json/JSONObjectTest.java
Thu Jun 27 19:28:59 2013
@@ -57,4 +57,10 @@ public class JSONObjectTest extends Test
         TestCase.assertTrue(obj.get(KEY).equals(null));
         TestCase.assertEquals("{\"" + KEY + "\":null}", obj.toString());
     }
+    
+    public void testParseLong() throws JSONException {
+        String jsonStr = "{\"longvalue\":\"13857270119014401\"}";
+        JSONObject obj = new JSONObject(jsonStr);
+        TestCase.assertEquals(13857270119014401L, obj.getLong("longvalue"));
+    }
 }



Mime
View raw message