fastjson ValueFilter 拦截过滤List 排序list

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 排序list)