You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by se...@apache.org on 2014/12/24 18:13:15 UTC
cxf git commit: [CXF-6166] Updating JsonMapObjectReaderWriter to
convert non-String JSON primitives to Long
Repository: cxf
Updated Branches:
refs/heads/master 286023087 -> eb9552724
[CXF-6166] Updating JsonMapObjectReaderWriter to convert non-String JSON primitives to Long
Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/eb955272
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/eb955272
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/eb955272
Branch: refs/heads/master
Commit: eb95527245146cf97fe7bb839dd01e7484215e13
Parents: 2860230
Author: Sergey Beryozkin <sb...@talend.com>
Authored: Wed Dec 24 17:12:57 2014 +0000
Committer: Sergey Beryozkin <sb...@talend.com>
Committed: Wed Dec 24 17:12:57 2014 +0000
----------------------------------------------------------------------
.../json/JsonMapObjectReaderWriter.java | 4 +-
.../json/JsonMapObjectReaderWriterTest.java | 50 ++++++++++++++++++++
2 files changed, 53 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cxf/blob/eb955272/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/json/JsonMapObjectReaderWriter.java
----------------------------------------------------------------------
diff --git a/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/json/JsonMapObjectReaderWriter.java b/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/json/JsonMapObjectReaderWriter.java
index e5859a7..343bad5 100644
--- a/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/json/JsonMapObjectReaderWriter.java
+++ b/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/json/JsonMapObjectReaderWriter.java
@@ -200,7 +200,9 @@ public class JsonMapObjectReaderWriter {
value = valueStr.substring(1, valueStr.length() - 1);
} else if ("true".equals(value) || "false".equals(value)) {
value = Boolean.valueOf(valueStr);
- }
+ } else {
+ value = Long.valueOf(valueStr);
+ }
return value;
}
http://git-wip-us.apache.org/repos/asf/cxf/blob/eb955272/rt/rs/extensions/providers/src/test/java/org/apache/cxf/jaxrs/provider/json/JsonMapObjectReaderWriterTest.java
----------------------------------------------------------------------
diff --git a/rt/rs/extensions/providers/src/test/java/org/apache/cxf/jaxrs/provider/json/JsonMapObjectReaderWriterTest.java b/rt/rs/extensions/providers/src/test/java/org/apache/cxf/jaxrs/provider/json/JsonMapObjectReaderWriterTest.java
new file mode 100644
index 0000000..dcee285
--- /dev/null
+++ b/rt/rs/extensions/providers/src/test/java/org/apache/cxf/jaxrs/provider/json/JsonMapObjectReaderWriterTest.java
@@ -0,0 +1,50 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.cxf.jaxrs.provider.json;
+
+import java.util.Collections;
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+public class JsonMapObjectReaderWriterTest extends Assert {
+
+ @Test
+ public void testWriteMap() throws Exception {
+ Map<String, Object> map = new LinkedHashMap<String, Object>();
+ map.put("a", "aValue");
+ map.put("b", 123);
+ map.put("c", Collections.singletonList("cValue"));
+ String json = new JsonMapObjectReaderWriter().toJson(map);
+ assertEquals("{\"a\":\"aValue\",\"b\":123,\"c\":[\"cValue\"]}",
+ json);
+ }
+ @Test
+ public void testReadMap() throws Exception {
+ String json = "{\"a\":\"aValue\",\"b\":123,\"c\":[\"cValue\"]}";
+ Map<String, Object> map = new JsonMapObjectReaderWriter().fromJson(json);
+ assertEquals(3, map.size());
+ assertEquals("aValue", map.get("a"));
+ assertEquals(123L, map.get("b"));
+ assertEquals(Collections.singletonList("cValue"), map.get("c"));
+ }
+}