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); + } + +}