json-lib有一个配置类JsonConfig
通过JsonConfig可以注册一个字段处理器
实现JsonValueProcessor接口即可

JsonConfig config = new JsonConfig();
config.registerJsonValueProcessor(java.sql.Date.class, new JsonValueProcessor() {
private SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd");

@Override
public Object processArrayValue(Object arg0, JsonConfig arg1) {
return null;
}

@Override
public Object processObjectValue(String arg0, Object arg1, JsonConfig arg2) {
return arg1 == null ? "" : sd.format(arg1);
}
});
JSONArray jsonArray = JSONArray.fromObject(articles, config);// 记得把config放进去

 

相关文章:

  • 2021-08-05
  • 2022-12-23
  • 2021-10-21
  • 2021-08-11
  • 2021-08-31
  • 2021-09-15
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-12-03
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-15
相关资源
相似解决方案