Skip to content

Commit

Permalink
upgrading jackson version to 2.9.4 (#591)
Browse files Browse the repository at this point in the history
  • Loading branch information
anuchandy authored Mar 19, 2019
1 parent caa5840 commit 16cad94
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.azure.common.implementation.serializer.jackson;

import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.azure.common.implementation.serializer.SerializerEncoding;
import org.junit.Test;

Expand All @@ -19,34 +19,30 @@ public void emptyMap() throws IOException {
}

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

@Test
Expand All @@ -56,4 +52,9 @@ public void mapWithEmptyKeyAndNonEmptyValue() throws IOException {
final JacksonAdapter serializer = new JacksonAdapter();
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.33.Final</netty.version>
<jackson.version>2.8.11</jackson.version>
<jackson.version>2.9.4</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 16cad94

Please sign in to comment.