@Test public void jsonToListTest(){ List<Integer> list=JsonUtils.jsonToList(listStr, Integer.class); Assert.assertNotNull(list); }
public static <T> List<T> jsonToList(String json,Class<T> clazz) { List<T> list =null; if(!Strings.isNullOrEmpty(json)){ T[] t = (T[]) Array.newInstance(clazz, 1024); try { t = (T[]) getInstance().readValue(json, t.getClass()); list= Arrays.asList(t); } catch (JsonGenerationException e) { logger.error(e.getMessage(),e); } catch (JsonMappingException e) { logger.error(e.getMessage(),e); } catch (IOException e) { logger.error(e.getMessage(),e); } } return list; }
JsonUtils { public static <T> List<T> jsonToList(String json,Class<T> clazz) { List<T> list =null; if(!Strings.isNullOrEmpty(json)){ T[] t = (T[]) Array.newInstance(clazz, 1024); try { t = (T[]) getInstance().readValue(json, t.getClass()); list= Arrays.asList(t); } catch (JsonGenerationException e) { logger.error(e.getMessage(),e); } catch (JsonMappingException e) { logger.error(e.getMessage(),e); } catch (IOException e) { logger.error(e.getMessage(),e); } } return list; } }
JsonUtils { public static <T> List<T> jsonToList(String json,Class<T> clazz) { List<T> list =null; if(!Strings.isNullOrEmpty(json)){ T[] t = (T[]) Array.newInstance(clazz, 1024); try { t = (T[]) getInstance().readValue(json, t.getClass()); list= Arrays.asList(t); } catch (JsonGenerationException e) { logger.error(e.getMessage(),e); } catch (JsonMappingException e) { logger.error(e.getMessage(),e); } catch (IOException e) { logger.error(e.getMessage(),e); } } return list; } private  JsonUtils(); }
JsonUtils { public static <T> List<T> jsonToList(String json,Class<T> clazz) { List<T> list =null; if(!Strings.isNullOrEmpty(json)){ T[] t = (T[]) Array.newInstance(clazz, 1024); try { t = (T[]) getInstance().readValue(json, t.getClass()); list= Arrays.asList(t); } catch (JsonGenerationException e) { logger.error(e.getMessage(),e); } catch (JsonMappingException e) { logger.error(e.getMessage(),e); } catch (IOException e) { logger.error(e.getMessage(),e); } } return list; } private  JsonUtils(); static ObjectMapper getInstance(); static T jsonToBean(String json,  Class<T> valueType); static String beanToJson(Object bean); static List<T> jsonToList(String json,Class<T> clazz); static String beanToJsonAndFmDate(Object channelList); }
JsonUtils { public static <T> List<T> jsonToList(String json,Class<T> clazz) { List<T> list =null; if(!Strings.isNullOrEmpty(json)){ T[] t = (T[]) Array.newInstance(clazz, 1024); try { t = (T[]) getInstance().readValue(json, t.getClass()); list= Arrays.asList(t); } catch (JsonGenerationException e) { logger.error(e.getMessage(),e); } catch (JsonMappingException e) { logger.error(e.getMessage(),e); } catch (IOException e) { logger.error(e.getMessage(),e); } } return list; } private  JsonUtils(); static ObjectMapper getInstance(); static T jsonToBean(String json,  Class<T> valueType); static String beanToJson(Object bean); static List<T> jsonToList(String json,Class<T> clazz); static String beanToJsonAndFmDate(Object channelList);  }