@Test public void testToEntityWithParamClass() throws IOException { JobHealth jobHealth = JsonUtil.toEntity(JOB_HEALTH_JSON, JobHealth.class); assertEquals(jobHealth.getJobCount(), 10); assertEquals(jobHealth.getHealthyJobCount(), 5); }
public static <T> T toEntity(String jsonStr, Class<T> type) throws IOException { if (StringUtils.isEmpty(jsonStr)) { LOGGER.warn("Json string {} is empty!", type); return null; } ObjectMapper mapper = new ObjectMapper(); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); return mapper.readValue(jsonStr, type); }
JsonUtil { public static <T> T toEntity(String jsonStr, Class<T> type) throws IOException { if (StringUtils.isEmpty(jsonStr)) { LOGGER.warn("Json string {} is empty!", type); return null; } ObjectMapper mapper = new ObjectMapper(); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); return mapper.readValue(jsonStr, type); } }
JsonUtil { public static <T> T toEntity(String jsonStr, Class<T> type) throws IOException { if (StringUtils.isEmpty(jsonStr)) { LOGGER.warn("Json string {} is empty!", type); return null; } ObjectMapper mapper = new ObjectMapper(); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); return mapper.readValue(jsonStr, type); }  }
JsonUtil { public static <T> T toEntity(String jsonStr, Class<T> type) throws IOException { if (StringUtils.isEmpty(jsonStr)) { LOGGER.warn("Json string {} is empty!", type); return null; } ObjectMapper mapper = new ObjectMapper(); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); return mapper.readValue(jsonStr, type); }  static String toJson(Object obj); static String toJsonWithFormat(Object obj); static T toEntity(String jsonStr, Class<T> type); static T toEntity(File file, TypeReference type); static T toEntity(InputStream in, TypeReference type); static T toEntity(String jsonStr, TypeReference type); }
JsonUtil { public static <T> T toEntity(String jsonStr, Class<T> type) throws IOException { if (StringUtils.isEmpty(jsonStr)) { LOGGER.warn("Json string {} is empty!", type); return null; } ObjectMapper mapper = new ObjectMapper(); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); return mapper.readValue(jsonStr, type); }  static String toJson(Object obj); static String toJsonWithFormat(Object obj); static T toEntity(String jsonStr, Class<T> type); static T toEntity(File file, TypeReference type); static T toEntity(InputStream in, TypeReference type); static T toEntity(String jsonStr, TypeReference type);  }