对JSONObject.fromObject 的处理
1.扩展JsonValueProcessor接口(注意对null的处理)
import net.sf.json.JsonConfig;
import net.sf.json.processors.JsonValueProcessor;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
/***
* 将Bean中的Timestamp转换为json中的日期字符串
* @author dxswzj@163.com
* */
public class DateJsonValueProcessor implements JsonValueProcessor {
public static final String Default_DATE_PATTERN ="yyyy-MM-dd";
private DateFormat dateFormat ;
public DateJsonValueProcessor(String datePattern){
try{
dateFormat = new SimpleDateFormat(datePattern);}
catch(Exception e ){
dateFormat = new SimpleDateFormat(Default_DATE_PATTERN);
}
}
public Object processArrayValue(Object value, JsonConfig jsonConfig) {
if(null!=value){
return pr