felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dav...@apache.org
Subject svn commit: r1779589 - in /felix/trunk/converter: schematizer/src/main/java/org/apache/felix/serializer/impl/json/ serializer/src/main/java/org/apache/felix/serializer/impl/json/ serializer/src/test/java/org/apache/felix/serializer/impl/json/
Date Fri, 20 Jan 2017 09:28:22 GMT
Author: davidb
Date: Fri Jan 20 09:28:22 2017
New Revision: 1779589

URL: http://svn.apache.org/viewvc?rev=1779589&view=rev
Log:
FELIX-5491 Serializer should allow empty key/values pairs when parsing

Patch applied on behalf of David Leangen with many thanks!

Modified:
    felix/trunk/converter/schematizer/src/main/java/org/apache/felix/serializer/impl/json/JsonParser.java
    felix/trunk/converter/serializer/src/main/java/org/apache/felix/serializer/impl/json/JsonParser.java
    felix/trunk/converter/serializer/src/test/java/org/apache/felix/serializer/impl/json/JsonParserTest.java

Modified: felix/trunk/converter/schematizer/src/main/java/org/apache/felix/serializer/impl/json/JsonParser.java
URL: http://svn.apache.org/viewvc/felix/trunk/converter/schematizer/src/main/java/org/apache/felix/serializer/impl/json/JsonParser.java?rev=1779589&r1=1779588&r2=1779589&view=diff
==============================================================================
--- felix/trunk/converter/schematizer/src/main/java/org/apache/felix/serializer/impl/json/JsonParser.java
(original)
+++ felix/trunk/converter/schematizer/src/main/java/org/apache/felix/serializer/impl/json/JsonParser.java
Fri Jan 20 09:28:22 2017
@@ -19,6 +19,7 @@ package org.apache.felix.serializer.impl
 import java.io.IOException;
 import java.io.InputStream;
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -141,6 +142,8 @@ public class JsonParser {
     }
 
     private static List<String> parseKeyValueListRaw(String jsonKeyValueList) {
+        if (jsonKeyValueList.trim().isEmpty())
+            return Collections.emptyList();
         jsonKeyValueList = jsonKeyValueList + ","; // append comma to simplify parsing
         List<String> elements = new ArrayList<>();
 

Modified: felix/trunk/converter/serializer/src/main/java/org/apache/felix/serializer/impl/json/JsonParser.java
URL: http://svn.apache.org/viewvc/felix/trunk/converter/serializer/src/main/java/org/apache/felix/serializer/impl/json/JsonParser.java?rev=1779589&r1=1779588&r2=1779589&view=diff
==============================================================================
--- felix/trunk/converter/serializer/src/main/java/org/apache/felix/serializer/impl/json/JsonParser.java
(original)
+++ felix/trunk/converter/serializer/src/main/java/org/apache/felix/serializer/impl/json/JsonParser.java
Fri Jan 20 09:28:22 2017
@@ -19,6 +19,7 @@ package org.apache.felix.serializer.impl
 import java.io.IOException;
 import java.io.InputStream;
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -149,6 +150,8 @@ public class JsonParser {
     }
 
     private static List<String> parseKeyValueListRaw(String jsonKeyValueList) {
+        if (jsonKeyValueList.trim().isEmpty())
+            return Collections.emptyList();
         jsonKeyValueList = jsonKeyValueList + ","; // append comma to simplify parsing
         List<String> elements = new ArrayList<>();
 

Modified: felix/trunk/converter/serializer/src/test/java/org/apache/felix/serializer/impl/json/JsonParserTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/converter/serializer/src/test/java/org/apache/felix/serializer/impl/json/JsonParserTest.java?rev=1779589&r1=1779588&r2=1779589&view=diff
==============================================================================
--- felix/trunk/converter/serializer/src/test/java/org/apache/felix/serializer/impl/json/JsonParserTest.java
(original)
+++ felix/trunk/converter/serializer/src/test/java/org/apache/felix/serializer/impl/json/JsonParserTest.java
Fri Jan 20 09:28:22 2017
@@ -17,6 +17,8 @@
 package org.apache.felix.serializer.impl.json;
 
 import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
 import java.util.Map;
 
 import org.junit.Test;
@@ -61,4 +63,15 @@ public class JsonParserTest {
         assertEquals(1, m.size());
         assertEquals(Arrays.asList("x", "y", "z"), m.get("abc"));
     }
+
+    @Test
+    public void testEmptyJsonArray() {
+        String json = "{\"abc\": {\"def\": []}}";
+        JsonParser jp = new JsonParser(json);
+        Map<String, Object> m = jp.getParsed();
+        assertEquals(1, m.size());
+        Map<String, Object> result = new HashMap<>();
+        result.put("def", Collections.emptyList());
+        assertEquals(result, m.get("abc"));
+    }
 }



Mime
View raw message