Object转json-常见问题总结
1、Object中有Timestamp、Date等日期类型数据
http://blog.csdn.net/without0815/article/details/7793851
public class JsonLibDateProcessor implements JsonValueProcessor {
/** 供调用的 static 实例 */
public static final JsonLibDateProcessor instance = new JsonLibDateProcessor();
private String format = "yyyy-MM-dd HH:mm:ss";
private SimpleDateFormat sdf = new SimpleDateFormat(format);
public Object processObjectValue(String key, Object value, JsonConfig jc) {
if(value == null){
return "";
}
if(value instanceof java.sql.Timestamp){
return sdf.format((java.sql.Timestamp)value);
}
if (value instanceof java.util.Date){
return sdf.format((java.util.Date) value);
}
return value.toString();
}
public Object processArrayValue(Object value, JsonConfig arg1) {
return null;
}
}
将时间正确格式化后,转json即可成功
http://blog.csdn.net/lalalove_yaya/article/details/3129834