@Test public void testEmployees() throws JsonParseException, JsonMappingException, IOException { Map<String, Employee> employeeMap = JSONParser.employees("/employees.json"); Assert.assertNotNull(employeeMap); Assert.assertEquals(2, employeeMap.size()); Employee employee123 = employeeMap.get("123"); Assert.assertNotNull(employee123); Assert.assertEquals("Abhijit", employee123.getName()); Assert.assertEquals("Software", employee123.getDepartment()); Employee employee456 = employeeMap.get("456"); Assert.assertNotNull(employee456); Assert.assertEquals("Sarkar", employee456.getName()); Assert.assertEquals("IT", employee456.getDepartment()); }
public static Map<String, Employee> employees(String file) throws JsonParseException, JsonMappingException, IOException { final TypeReference<Map<String, Employee>> employeeMapType = new TypeReference<Map<String, Employee>>() { }; return new ObjectMapper().readValue(JSONParser.class.getResource(file), employeeMapType); }
JSONParser { public static Map<String, Employee> employees(String file) throws JsonParseException, JsonMappingException, IOException { final TypeReference<Map<String, Employee>> employeeMapType = new TypeReference<Map<String, Employee>>() { }; return new ObjectMapper().readValue(JSONParser.class.getResource(file), employeeMapType); } }
JSONParser { public static Map<String, Employee> employees(String file) throws JsonParseException, JsonMappingException, IOException { final TypeReference<Map<String, Employee>> employeeMapType = new TypeReference<Map<String, Employee>>() { }; return new ObjectMapper().readValue(JSONParser.class.getResource(file), employeeMapType); }  }
JSONParser { public static Map<String, Employee> employees(String file) throws JsonParseException, JsonMappingException, IOException { final TypeReference<Map<String, Employee>> employeeMapType = new TypeReference<Map<String, Employee>>() { }; return new ObjectMapper().readValue(JSONParser.class.getResource(file), employeeMapType); }  static Map<String, Employee> employees(String file); }
JSONParser { public static Map<String, Employee> employees(String file) throws JsonParseException, JsonMappingException, IOException { final TypeReference<Map<String, Employee>> employeeMapType = new TypeReference<Map<String, Employee>>() { }; return new ObjectMapper().readValue(JSONParser.class.getResource(file), employeeMapType); }  static Map<String, Employee> employees(String file);  }