Skip to content

Commit

Permalink
Revert Jackson version to 2.8.11 and add JacksonSerializer tests (Azu…
Browse files Browse the repository at this point in the history
  • Loading branch information
Dan Schulte authored Jan 2, 2018
1 parent 430580b commit 91dc54e
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package com.microsoft.rest.v2.serializer;

import com.fasterxml.jackson.databind.JsonMappingException;
import org.junit.Test;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import static org.junit.Assert.*;

public class JacksonAdapterTests {
@Test
public void emptyMap() throws IOException {
final Map<String,String> map = new HashMap<>();
final JacksonAdapter serializer = new JacksonAdapter();
assertEquals("{}", serializer.serialize(map));
}

@Test
public void mapWithNullKey() {
final Map<String,String> map = new HashMap<>();
map.put(null, null);
final JacksonAdapter serializer = new JacksonAdapter();
try {
serializer.serialize(map);
fail();
}
catch (Exception e) {
assertEquals(JsonMappingException.class, e.getClass());
assertTrue(e.getMessage().contains("Null key for a Map not allowed in JSON"));
}
}

@Test
public void mapWithEmptyKeyAndNullValue() throws IOException {
final Map<String,String> map = new HashMap<>();
map.put("", null);
final JacksonAdapter serializer = new JacksonAdapter();
assertEquals("{\"\":null}", serializer.serialize(map));
}

@Test
public void mapWithEmptyKeyAndEmptyValue() throws IOException {
final Map<String,String> map = new HashMap<>();
map.put("", "");
final JacksonAdapter serializer = new JacksonAdapter();
assertEquals("{\"\":\"\"}", serializer.serialize(map));
}

@Test
public void mapWithEmptyKeyAndNonEmptyValue() throws IOException {
final Map<String,String> map = new HashMap<>();
map.put("", "test");
final JacksonAdapter serializer = new JacksonAdapter();
assertEquals("{\"\":\"test\"}", serializer.serialize(map));
}
}
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,12 @@
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-joda</artifactId>
<version>2.9.3</version>
<version>2.8.11</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-xml</artifactId>
<version>2.9.3</version>
<version>2.8.11</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
Expand Down

0 comments on commit 91dc54e

Please sign in to comment.