@Test public void test_fromJson_class_fail() { String str = "{ 123}"; Assertions.assertThrows(HyenaServiceException.class, () -> { JsonUtils.fromJson(str, BaseResponse.class); Assertions.fail(); }); }
public static <T> T fromJson(String jsonString, Class<T> clazz) { ObjectMapper mapper = new ObjectMapper(); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); mapper.configure(DeserializationFeature.USE_BIG_DECIMAL_FOR_FLOATS, true); try { return mapper.readValue(jsonString, clazz); } catch (IOException e) { logger.error(e.getMessage(), e); throw new HyenaServiceException(" result can not converto to Object"); } }
JsonUtils { public static <T> T fromJson(String jsonString, Class<T> clazz) { ObjectMapper mapper = new ObjectMapper(); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); mapper.configure(DeserializationFeature.USE_BIG_DECIMAL_FOR_FLOATS, true); try { return mapper.readValue(jsonString, clazz); } catch (IOException e) { logger.error(e.getMessage(), e); throw new HyenaServiceException(" result can not converto to Object"); } } }
JsonUtils { public static <T> T fromJson(String jsonString, Class<T> clazz) { ObjectMapper mapper = new ObjectMapper(); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); mapper.configure(DeserializationFeature.USE_BIG_DECIMAL_FOR_FLOATS, true); try { return mapper.readValue(jsonString, clazz); } catch (IOException e) { logger.error(e.getMessage(), e); throw new HyenaServiceException(" result can not converto to Object"); } }  }
JsonUtils { public static <T> T fromJson(String jsonString, Class<T> clazz) { ObjectMapper mapper = new ObjectMapper(); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); mapper.configure(DeserializationFeature.USE_BIG_DECIMAL_FOR_FLOATS, true); try { return mapper.readValue(jsonString, clazz); } catch (IOException e) { logger.error(e.getMessage(), e); throw new HyenaServiceException(" result can not converto to Object"); } }  static T fromJson(String jsonString, Class<T> clazz); static T fromJson(String json, TypeReference<T> typereference); static String toJsonString(Object obj); }
JsonUtils { public static <T> T fromJson(String jsonString, Class<T> clazz) { ObjectMapper mapper = new ObjectMapper(); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); mapper.configure(DeserializationFeature.USE_BIG_DECIMAL_FOR_FLOATS, true); try { return mapper.readValue(jsonString, clazz); } catch (IOException e) { logger.error(e.getMessage(), e); throw new HyenaServiceException(" result can not converto to Object"); } }  static T fromJson(String jsonString, Class<T> clazz); static T fromJson(String json, TypeReference<T> typereference); static String toJsonString(Object obj);  }