use of com.baeldung.jackson.entities.MyPair in project tutorials by eugenp.
the class JacksonMapDeserializeUnitTest method whenObjectStringMapDeserialize_thenCorrect.
@Test
public void whenObjectStringMapDeserialize_thenCorrect() throws JsonParseException, JsonMappingException, IOException {
final String jsonInput = "{\"Abbott and Costello\":\"Comedy\"}";
TypeReference<HashMap<MyPair, String>> typeRef = new TypeReference<HashMap<MyPair, String>>() {
};
map = mapper.readValue(jsonInput, typeRef);
Assert.assertEquals("Comedy", map.get(new MyPair("Abbott", "Costello")));
ClassWithAMap classWithMap = mapper.readValue(jsonInput, ClassWithAMap.class);
Assert.assertEquals("Comedy", classWithMap.getMap().get(new MyPair("Abbott", "Costello")));
}
use of com.baeldung.jackson.entities.MyPair in project tutorials by eugenp.
the class JacksonMapDeserializeUnitTest method whenObjectObjectMapDeserialize_thenCorrect.
@Test
public void whenObjectObjectMapDeserialize_thenCorrect() throws JsonParseException, JsonMappingException, IOException {
final String jsonInput = "{\"Abbott and Costello\" : \"Comedy and 1940s\"}";
TypeReference<HashMap<MyPair, MyPair>> typeRef = new TypeReference<HashMap<MyPair, MyPair>>() {
};
cmap = mapper.readValue(jsonInput, typeRef);
Assert.assertEquals(new MyPair("Comedy", "1940s"), cmap.get(new MyPair("Abbott", "Costello")));
}
use of com.baeldung.jackson.entities.MyPair in project tutorials by eugenp.
the class JacksonMapSerializeUnitTest method whenCustomObjectObjectMapSerialize_thenCorrect.
@Test
public void whenCustomObjectObjectMapSerialize_thenCorrect() throws JsonProcessingException {
cmap = new HashMap<>();
mapKey = new MyPair("Abbott", "Costello");
mapValue = new MyPair("Comedy", "1940's");
cmap.put(mapKey, mapValue);
final String jsonResult = mapper.writeValueAsString(cmap);
Assert.assertEquals("{\"Abbott and Costello\":\"Comedy and 1940's\"}", jsonResult);
}
use of com.baeldung.jackson.entities.MyPair in project tutorials by eugenp.
the class JacksonMapSerializeUnitTest method whenCustomObjectStringMapSerialize_thenCorrect.
@Test
public void whenCustomObjectStringMapSerialize_thenCorrect() throws JsonProcessingException {
map = new HashMap<>();
MyPair key = new MyPair("Abbott", "Costello");
map.put(key, "Comedy");
final String jsonResult = mapper.writeValueAsString(map);
Assert.assertEquals("{\"Abbott and Costello\":\"Comedy\"}", jsonResult);
}
Aggregations