Skip to content

Commit

Permalink
Upgrading jackson from 2.8.11 to 2.9.6
Browse files Browse the repository at this point in the history
  • Loading branch information
anuchandy committed Apr 18, 2019
1 parent f30c79b commit a01b916
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 21 deletions.
Original file line number Diff line number Diff line change
@@ -1,58 +1,60 @@
package com.microsoft.rest.v2.serializer;

import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.microsoft.rest.v2.protocol.SerializerEncoding;
import org.junit.Test;

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

import static org.junit.Assert.*;
import static org.junit.Assert.assertEquals;

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));
assertEquals("{}", serializer.serialize(map, SerializerEncoding.JSON));
}

@Test
public void mapWithNullKey() {
public void mapWithNullKey() throws IOException {
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"));
}
assertEquals("{}", serializer.serialize(map, SerializerEncoding.JSON));
}

@Test
public void mapWithEmptyKeyAndNullValue() throws IOException {
final Map<String,String> map = new HashMap<>();
map.put("", null);
final MapHolder mapHolder = new MapHolder();
mapHolder.map = new HashMap<>();
mapHolder.map.put("", null);

final JacksonAdapter serializer = new JacksonAdapter();
assertEquals("{\"\":null}", serializer.serialize(map));
assertEquals("{\"map\":{\"\":null}}", serializer.serialize(mapHolder, SerializerEncoding.JSON));
}

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

@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));
assertEquals("{\"\":\"test\"}", serializer.serialize(map, SerializerEncoding.JSON));
}

private static class MapHolder {
@JsonInclude(content = JsonInclude.Include.ALWAYS)
public Map<String,String> map = new HashMap<>();
}
}
}
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

<properties>
<netty.version>4.1.28.Final</netty.version>
<jackson.version>2.8.11</jackson.version>
<jackson.version>2.9.6</jackson.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<legal><![CDATA[[INFO] Any downloads listed may be third party software. Microsoft grants you no rights for third party software.]]></legal>
</properties>
Expand Down

0 comments on commit a01b916

Please sign in to comment.