From 675bb3506a8d08f8e4d2a340b084019c40492a7c Mon Sep 17 00:00:00 2001 From: Drew Michel Date: Sun, 25 Nov 2018 09:50:20 -0500 Subject: [PATCH] [json] regression test for null value MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A JSON null value is being translated to a “null” string. Was supposed to be fixed in https://github.com/FasterXML/jackson-databind/issues/1842 but it doesn’t appear to be. --- modules/json/pom.xml | 8 +++++ .../ffwd/json/JsonObjectMapperDecoder.java | 2 +- .../json/JsonObjectMapperDecoderTest.java | 29 +++++++++++++++++++ 3 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 modules/json/src/test/java/com/spotify/ffwd/json/JsonObjectMapperDecoderTest.java diff --git a/modules/json/pom.xml b/modules/json/pom.xml index 9f268b29..435ed97a 100644 --- a/modules/json/pom.xml +++ b/modules/json/pom.xml @@ -23,5 +23,13 @@ com.spotify.ffwd ffwd-api + + + + junit + junit + test + + diff --git a/modules/json/src/main/java/com/spotify/ffwd/json/JsonObjectMapperDecoder.java b/modules/json/src/main/java/com/spotify/ffwd/json/JsonObjectMapperDecoder.java index 6c78a656..547c9985 100644 --- a/modules/json/src/main/java/com/spotify/ffwd/json/JsonObjectMapperDecoder.java +++ b/modules/json/src/main/java/com/spotify/ffwd/json/JsonObjectMapperDecoder.java @@ -169,7 +169,7 @@ private double decodeDouble(JsonNode tree, String name) { return n.asDouble(); } - private String decodeString(JsonNode tree, String name) { + String decodeString(JsonNode tree, String name) { final JsonNode n = tree.get(name); if (n == null) { diff --git a/modules/json/src/test/java/com/spotify/ffwd/json/JsonObjectMapperDecoderTest.java b/modules/json/src/test/java/com/spotify/ffwd/json/JsonObjectMapperDecoderTest.java new file mode 100644 index 00000000..a3d52938 --- /dev/null +++ b/modules/json/src/test/java/com/spotify/ffwd/json/JsonObjectMapperDecoderTest.java @@ -0,0 +1,29 @@ +package com.spotify.ffwd.json; + +import static junit.framework.TestCase.assertNull; + +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import java.io.IOException; +import org.junit.Before; +import org.junit.Test; + +public class JsonObjectMapperDecoderTest { + private final ObjectMapper mapper = new ObjectMapper(); + + private JsonObjectMapperDecoder j; + + @Before + public void setup() { + j = new JsonObjectMapperDecoder(); + } + + @Test + public void nullKey() throws IOException { + final JsonNode json = mapper.readTree("{\"key\": null}"); + final String key = j.decodeString(json, "key"); + + assertNull(key); + } + +}