@Test public void beanToJsonTest(){ Json json=new Json(); Map<String,Integer> map=Maps.newHashMap(); List<Integer> list=Lists.newArrayList(1,2,3,4); json.setName("张三"); json.setAge(22); json.setMap(map); json.setList(list); json.setDate(new Date()); System.out.println(JsonUtils.beanToJson(json)); }
public static String beanToJson(Object bean){ try { return getInstance().writeValueAsString(bean); } 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 null; }
JsonUtils { public static String beanToJson(Object bean){ try { return getInstance().writeValueAsString(bean); } 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 null; } }
JsonUtils { public static String beanToJson(Object bean){ try { return getInstance().writeValueAsString(bean); } 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 null; } private  JsonUtils(); }
JsonUtils { public static String beanToJson(Object bean){ try { return getInstance().writeValueAsString(bean); } 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 null; } 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 String beanToJson(Object bean){ try { return getInstance().writeValueAsString(bean); } 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 null; } 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);  }