Skip to content

Commit

Permalink
[json] regression test for null value
Browse files Browse the repository at this point in the history
A JSON null value is being translated to a “null” string.

Was supposed to be fixed in FasterXML/jackson-databind#1842 but it doesn’t appear to be.
  • Loading branch information
dmichel1 committed Nov 25, 2018
1 parent d9459c4 commit fadd5a9
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
8 changes: 8 additions & 0 deletions modules/json/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,13 @@
<groupId>com.spotify.ffwd</groupId>
<artifactId>ffwd-api</artifactId>
</dependency>

<!-- testing -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}

}

0 comments on commit fadd5a9

Please sign in to comment.