美文网首页
fastjson ValueFilter 拦截过滤List 排

fastjson ValueFilter 拦截过滤List 排

作者: forstar | 来源:发表于2016-10-12 13:59 被阅读0次

import com.alibaba.fastjson.JSON;

import com.alibaba.fastjson.serializer.ValueFilter;

ListresultZhibaoList= zhibaoService.queryZhibaoList(zhibao);

//拦截,处理日期格式

ValueFilter valueFilter = new ValueFilter() {

@Override

public Object process(Object obj, String key, Object value) {

if(value instanceof Timestamp){

Timestamp timestamp = (Timestamp) value;

return DateUtils.parseDate(timestamp,"yyyy-MM-dd");

}else{

return value;

}

}

};

//List排序Collections.sort(resultZhibaoList, new Comparator() {

public int compare(ResultZhibao arg0, ResultZhibao arg1) {

return arg1.getZhibaoNumber().compareTo(arg0.getZhibaoNumber());

}

});

//List 转 JSON

String dataList = JSON.toJSONString(resultZhibaoList, valueFilter);

相关文章

网友评论

      本文标题:fastjson ValueFilter 拦截过滤List 排

      本文链接:https://www.haomeiwen.com/subject/zyjiyttx.html