java中需要一些toString的操作,常见的使用过common-lang中的ToStringBuilder的reflectionToString方法,不过不适用array,list,等类,不过JSONObject倒是使用上方便很多,不过如果可以,Gson的toJson也是个很好用的方法。
还有一些针对sql查询,需要将bean对象转成Map的方法,
BeanUtilsBean.getInstance().describe(object);倒是个不错的方法,不过老版本需要注意,对date的处理会有点问题,这里可以考虑
ConvertUtilsBean convertUtils = new ConvertUtilsBean();
//修复 BeanUtilsBean describe方法不支持java.util.Date的bug
convertUtils.register(new DateConverter(), Date.class);
//转换
BeanUtilsBean beanUtils = new BeanUtilsBean(convertUtils,new PropertyUtilsBean());
beanUtils.describe()
SimpleDateFormat的线程安全替代实现:
org.apache.commons.lang.time.FastDateFormat