You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by sb...@apache.org on 2016/06/28 13:06:57 UTC

[10/50] [abbrv] ignite git commit: IGNITE-3277 Fixed null key serialization.

IGNITE-3277 Fixed null key serialization.


Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/482015e9
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/482015e9
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/482015e9

Branch: refs/heads/ignite-1232
Commit: 482015e9924425c70901fdae36222110af6e6c16
Parents: 0c5db20
Author: Alexey Kuznetsov <ak...@apache.org>
Authored: Tue Jun 21 17:49:47 2016 +0700
Committer: Alexey Kuznetsov <ak...@apache.org>
Committed: Tue Jun 21 17:49:47 2016 +0700

----------------------------------------------------------------------
 .../JettyRestProcessorAbstractSelfTest.java     | 33 ++++++++++++++++++++
 .../http/jetty/GridJettyObjectMapper.java       | 23 +++++++++++---
 2 files changed, 52 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/482015e9/modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/JettyRestProcessorAbstractSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/JettyRestProcessorAbstractSelfTest.java b/modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/JettyRestProcessorAbstractSelfTest.java
index ad667ed..81bffcf 100644
--- a/modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/JettyRestProcessorAbstractSelfTest.java
+++ b/modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/JettyRestProcessorAbstractSelfTest.java
@@ -339,6 +339,39 @@ public abstract class JettyRestProcessorAbstractSelfTest extends AbstractRestPro
     /**
      * @throws Exception If failed.
      */
+    public void testNullMapKeyAndValue()  throws Exception {
+        Map<String, String> map1 = new HashMap<>();
+        map1.put(null, null);
+        map1.put("key", "value");
+
+        jcache().put("mapKey1", map1);
+
+        String ret = content(F.asMap("cmd", GridRestCommand.CACHE_GET.key(), "key", "mapKey1"));
+
+        info("Get command result: " + ret);
+
+        JsonNode res = jsonResponse(ret);
+
+        assertEquals(F.asMap("", null, "key", "value"), JSON_MAPPER.treeToValue(res, HashMap.class));
+
+        Map<String, String> map2 = new HashMap<>();
+        map2.put(null, "value");
+        map2.put("key", null);
+
+        jcache().put("mapKey2", map2);
+
+        ret = content(F.asMap("cmd", GridRestCommand.CACHE_GET.key(), "key", "mapKey2"));
+
+        info("Get command result: " + ret);
+
+        res = jsonResponse(ret);
+
+        assertEquals(F.asMap("", "value", "key", null), JSON_MAPPER.treeToValue(res, HashMap.class));
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
     public void testSimpleObject()  throws Exception {
         SimplePerson p = new SimplePerson(1, "Test", java.sql.Date.valueOf("1977-01-26"), 1000.55, 39, "CIO", 25);
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/482015e9/modules/rest-http/src/main/java/org/apache/ignite/internal/processors/rest/protocols/http/jetty/GridJettyObjectMapper.java
----------------------------------------------------------------------
diff --git a/modules/rest-http/src/main/java/org/apache/ignite/internal/processors/rest/protocols/http/jetty/GridJettyObjectMapper.java b/modules/rest-http/src/main/java/org/apache/ignite/internal/processors/rest/protocols/http/jetty/GridJettyObjectMapper.java
index f09b583..6289bdb 100644
--- a/modules/rest-http/src/main/java/org/apache/ignite/internal/processors/rest/protocols/http/jetty/GridJettyObjectMapper.java
+++ b/modules/rest-http/src/main/java/org/apache/ignite/internal/processors/rest/protocols/http/jetty/GridJettyObjectMapper.java
@@ -19,6 +19,7 @@ package org.apache.ignite.internal.processors.rest.protocols.http.jetty;
 
 import com.fasterxml.jackson.core.JsonGenerator;
 import com.fasterxml.jackson.databind.BeanProperty;
+import com.fasterxml.jackson.databind.JavaType;
 import com.fasterxml.jackson.databind.JsonMappingException;
 import com.fasterxml.jackson.databind.JsonSerializer;
 import com.fasterxml.jackson.databind.ObjectMapper;
@@ -67,8 +68,16 @@ public class GridJettyObjectMapper extends ObjectMapper {
         registerModule(module);
     }
 
+    /** Custom {@code null} key serializer. */
+    private static final JsonSerializer<Object> NULL_KEY_SERIALIZER = new JsonSerializer<Object>() {
+        /** {@inheritDoc} */
+        @Override public void serialize(Object val, JsonGenerator gen, SerializerProvider ser) throws IOException {
+            gen.writeFieldName("");
+        }
+    };
+
     /** Custom {@code null} value serializer. */
-    private static final JsonSerializer<Object> NULL_SERIALIZER = new JsonSerializer<Object>() {
+    private static final JsonSerializer<Object> NULL_VALUE_SERIALIZER = new JsonSerializer<Object>() {
         /** {@inheritDoc} */
         @Override public void serialize(Object val, JsonGenerator gen, SerializerProvider ser) throws IOException {
             gen.writeNull();
@@ -76,7 +85,7 @@ public class GridJettyObjectMapper extends ObjectMapper {
     };
 
     /** Custom {@code null} string serializer. */
-    private static final JsonSerializer<Object> NULL_STRING_SERIALIZER = new JsonSerializer<Object>() {
+    private static final JsonSerializer<Object> NULL_STRING_VALUE_SERIALIZER = new JsonSerializer<Object>() {
         /** {@inheritDoc} */
         @Override public void serialize(Object val, JsonGenerator gen, SerializerProvider ser) throws IOException {
             gen.writeString("");
@@ -111,11 +120,17 @@ public class GridJettyObjectMapper extends ObjectMapper {
         }
 
         /** {@inheritDoc} */
+        @Override public JsonSerializer<Object> findNullKeySerializer(JavaType serializationType,
+            BeanProperty prop) throws JsonMappingException {
+            return NULL_KEY_SERIALIZER;
+        }
+
+        /** {@inheritDoc} */
         @Override public JsonSerializer<Object> findNullValueSerializer(BeanProperty prop) throws JsonMappingException {
             if (prop.getType().getRawClass() == String.class)
-                return NULL_STRING_SERIALIZER;
+                return NULL_STRING_VALUE_SERIALIZER;
 
-            return NULL_SERIALIZER;
+            return NULL_VALUE_SERIALIZER;
         }
     }