import java.util.HashMap;
import net.sf.json.JSONObject;
import net.sf.json.JsonConfig;
import net.sf.json.processors.JsDateJsonBeanProcessor;
/**
* @author jarod
*
*/
public class JsonDate {
public static void main(String[] args) {
// json-lib默认不支持java.sql.Date的序列化,要序列化自己的类,实现一个BeanProcessor处理即可
JsDateJsonBeanProcessor beanProcessor = new JsDateJsonBeanProcessor();
java.sql.Date d = new java.sql.Date(System.currentTimeMillis());
// 直接序列化
JsonConfig config = new JsonConfig();
JSONObject json = beanProcessor.processBean(d, config);
System.out.println(json.toString());
// 序列化含java.sql.Date作为属性值的bean
HashMap m = new HashMap();
m.put("date", d);
config.registerJsonBeanProcessor(java.sql.Date.class, beanProcessor);
json = JSONObject.fromObject(m, config);
System.out.println(json.toString());
}
}