diff --git a/jackson/src/test/java/com/baeldung/jackson/deserialization/JacksonMapDeserializeTest.java b/jackson/src/test/java/com/baeldung/jackson/deserialization/JacksonMapDeserializeTest.java index 04eb89306b..5021abaac1 100644 --- a/jackson/src/test/java/com/baeldung/jackson/deserialization/JacksonMapDeserializeTest.java +++ b/jackson/src/test/java/com/baeldung/jackson/deserialization/JacksonMapDeserializeTest.java @@ -18,13 +18,13 @@ public class JacksonMapDeserializeTest { private Map map; private Map cmap; + final ObjectMapper mapper = new ObjectMapper(); @Test public void whenSimpleMapDeserialize_thenCorrect() throws JsonParseException, JsonMappingException, IOException { final String jsonInput = "{\"key\": \"value\"}"; - final ObjectMapper mapper = new ObjectMapper(); TypeReference> typeRef = new TypeReference>() { }; @@ -38,7 +38,6 @@ public class JacksonMapDeserializeTest { throws JsonParseException, JsonMappingException, IOException { final String jsonInput = "{\"Abbott and Costello\":\"Comedy\"}"; - final ObjectMapper mapper = new ObjectMapper(); TypeReference> typeRef = new TypeReference>() { }; @@ -59,7 +58,6 @@ public class JacksonMapDeserializeTest { throws JsonParseException, JsonMappingException, IOException { final String jsonInput = "{\"Abbott and Costello\" : \"Comedy and 1940s\"}"; - final ObjectMapper mapper = new ObjectMapper(); TypeReference> typeRef = new TypeReference>() { }; diff --git a/jackson/src/test/java/com/baeldung/jackson/serialization/JacksonMapSerializeTest.java b/jackson/src/test/java/com/baeldung/jackson/serialization/JacksonMapSerializeTest.java index 841b12ca03..a5ee76f3b8 100644 --- a/jackson/src/test/java/com/baeldung/jackson/serialization/JacksonMapSerializeTest.java +++ b/jackson/src/test/java/com/baeldung/jackson/serialization/JacksonMapSerializeTest.java @@ -26,6 +26,8 @@ public class JacksonMapSerializeTest { @JsonSerialize(keyUsing = MyPairSerializer.class) private MyPair mapValue; + final ObjectMapper mapper = new ObjectMapper(); + @Test public void whenSimpleMapSerialize_thenCorrect() throws JsonProcessingException { @@ -33,7 +35,6 @@ public class JacksonMapSerializeTest { Map map = new HashMap<>(); map.put("key", "value"); - final ObjectMapper mapper = new ObjectMapper(); final String jsonResult = mapper.writeValueAsString(map); Assert.assertEquals("{\"key\":\"value\"}", jsonResult); @@ -47,7 +48,6 @@ public class JacksonMapSerializeTest { MyPair key = new MyPair("Abbott", "Costello"); map.put(key, "Comedy"); - final ObjectMapper mapper = new ObjectMapper(); final String jsonResult = mapper.writeValueAsString(map); Assert.assertEquals("{\"Abbott and Costello\":\"Comedy\"}", jsonResult); @@ -62,7 +62,6 @@ public class JacksonMapSerializeTest { mapValue = new MyPair("Comedy", "1940's"); cmap.put(mapKey, mapValue); - final ObjectMapper mapper = new ObjectMapper(); final String jsonResult = mapper.writeValueAsString(cmap); Assert.assertEquals("{\"Abbott and Costello\":\"Comedy and 1940's\"}",