Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 337C6200B17 for ; Tue, 21 Jun 2016 18:26:49 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 32205160A60; Tue, 21 Jun 2016 16:26:49 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 56E9A160A68 for ; Tue, 21 Jun 2016 18:26:48 +0200 (CEST) Received: (qmail 48611 invoked by uid 500); 21 Jun 2016 16:26:47 -0000 Mailing-List: contact commits-help@ignite.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@ignite.apache.org Delivered-To: mailing list commits@ignite.apache.org Received: (qmail 48473 invoked by uid 99); 21 Jun 2016 16:26:47 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 21 Jun 2016 16:26:47 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 47411DFC13; Tue, 21 Jun 2016 16:26:47 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: av@apache.org To: commits@ignite.apache.org Date: Tue, 21 Jun 2016 16:26:52 -0000 Message-Id: In-Reply-To: <3a38abfedecc4089b6b93463bf29a020@git.apache.org> References: <3a38abfedecc4089b6b93463bf29a020@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [6/8] ignite git commit: IGNITE-3277 Fixed null key serialization. archived-at: Tue, 21 Jun 2016 16:26:49 -0000 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/dc28c828 Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/dc28c828 Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/dc28c828 Branch: refs/heads/ignite-3230 Commit: dc28c828aa92b98a7c1b8fdc1a6d6f1e27a2c576 Parents: 9bdb41c Author: Alexey Kuznetsov Authored: Tue Jun 21 17:46:50 2016 +0700 Committer: Alexey Kuznetsov Committed: Tue Jun 21 17:46:50 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/dc28c828/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 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 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/dc28c828/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 NULL_KEY_SERIALIZER = new JsonSerializer() { + /** {@inheritDoc} */ + @Override public void serialize(Object val, JsonGenerator gen, SerializerProvider ser) throws IOException { + gen.writeFieldName(""); + } + }; + /** Custom {@code null} value serializer. */ - private static final JsonSerializer NULL_SERIALIZER = new JsonSerializer() { + private static final JsonSerializer NULL_VALUE_SERIALIZER = new JsonSerializer() { /** {@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 NULL_STRING_SERIALIZER = new JsonSerializer() { + private static final JsonSerializer NULL_STRING_VALUE_SERIALIZER = new JsonSerializer() { /** {@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 findNullKeySerializer(JavaType serializationType, + BeanProperty prop) throws JsonMappingException { + return NULL_KEY_SERIALIZER; + } + + /** {@inheritDoc} */ @Override public JsonSerializer 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; } }