Skip to content

Commit 87be4ed

Browse files
nboseckerpivovarit
authored andcommitted
Moved objectmapper to class level, one per class (eugenp#1558)
* Solr w Apache SolrJ * Solr w Apache SolrJ * updated test names and moved add to @before method * create apache-solrj module, moved code from spring-data-solr * More examples for indexing,delete,and query for solrj * More examples for indexing,delete,and query for solrj * Jackson Map Serialize/Deserialize * Jackson Map Serialize/Deserialize * Jackson version update * keydeserializer code added * keydeserializer code added * remove explicit types from map instantion * one objectmapper per class
1 parent 2c50b4f commit 87be4ed

2 files changed

Lines changed: 3 additions & 6 deletions

File tree

‎jackson/src/test/java/com/baeldung/jackson/deserialization/JacksonMapDeserializeTest.java‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ public class JacksonMapDeserializeTest {
1818

1919
private Map<MyPair, String> map;
2020
private Map<MyPair, MyPair> cmap;
21+
final ObjectMapper mapper = new ObjectMapper();
2122

2223
@Test
2324
public void whenSimpleMapDeserialize_thenCorrect()
2425
throws JsonParseException, JsonMappingException, IOException {
2526

2627
final String jsonInput = "{\"key\": \"value\"}";
27-
final ObjectMapper mapper = new ObjectMapper();
2828
TypeReference<HashMap<String, String>> typeRef = new TypeReference<HashMap<String, String>>() {
2929
};
3030

@@ -38,7 +38,6 @@ public void whenObjectStringMapDeserialize_thenCorrect()
3838
throws JsonParseException, JsonMappingException, IOException {
3939

4040
final String jsonInput = "{\"Abbott and Costello\":\"Comedy\"}";
41-
final ObjectMapper mapper = new ObjectMapper();
4241

4342
TypeReference<HashMap<MyPair, String>> typeRef = new TypeReference<HashMap<MyPair, String>>() {
4443
};
@@ -59,7 +58,6 @@ public void whenObjectObjectMapDeserialize_thenCorrect()
5958
throws JsonParseException, JsonMappingException, IOException {
6059

6160
final String jsonInput = "{\"Abbott and Costello\" : \"Comedy and 1940s\"}";
62-
final ObjectMapper mapper = new ObjectMapper();
6361
TypeReference<HashMap<MyPair, MyPair>> typeRef = new TypeReference<HashMap<MyPair, MyPair>>() {
6462
};
6563

‎jackson/src/test/java/com/baeldung/jackson/serialization/JacksonMapSerializeTest.java‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,15 @@ public class JacksonMapSerializeTest {
2626
@JsonSerialize(keyUsing = MyPairSerializer.class)
2727
private MyPair mapValue;
2828

29+
final ObjectMapper mapper = new ObjectMapper();
30+
2931
@Test
3032
public void whenSimpleMapSerialize_thenCorrect()
3133
throws JsonProcessingException {
3234

3335
Map<String, String> map = new HashMap<>();
3436
map.put("key", "value");
3537

36-
final ObjectMapper mapper = new ObjectMapper();
3738
final String jsonResult = mapper.writeValueAsString(map);
3839

3940
Assert.assertEquals("{\"key\":\"value\"}", jsonResult);
@@ -47,7 +48,6 @@ public void whenCustomObjectStringMapSerialize_thenCorrect()
4748
MyPair key = new MyPair("Abbott", "Costello");
4849
map.put(key, "Comedy");
4950

50-
final ObjectMapper mapper = new ObjectMapper();
5151
final String jsonResult = mapper.writeValueAsString(map);
5252

5353
Assert.assertEquals("{\"Abbott and Costello\":\"Comedy\"}", jsonResult);
@@ -62,7 +62,6 @@ public void whenCustomObjectObjectMapSerialize_thenCorrect()
6262
mapValue = new MyPair("Comedy", "1940's");
6363
cmap.put(mapKey, mapValue);
6464

65-
final ObjectMapper mapper = new ObjectMapper();
6665
final String jsonResult = mapper.writeValueAsString(cmap);
6766

6867
Assert.assertEquals("{\"Abbott and Costello\":\"Comedy and 1940's\"}",

0 commit comments

Comments
 (0)