码迷,mamicode.com
首页 > Web开发 > 详细

对象转JSON正则查找替换

时间:2020-11-26 15:05:39      阅读:9      评论:0      收藏:0      [点我收藏+]

标签:cas   app   package   export   cti   fas   UNC   mes   import   

package com.smil.gws.wbd.labor;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.smil.gws.common.utils.GwsReportUtils;
import com.smil.gws.report.vo.WcmWarrantyClaimExportView;
import org.bouncycastle.util.StringList;

import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class test {
public static void main(String[] args) {
WcmWarrantyClaimExportView view = new WcmWarrantyClaimExportView();
view.setStatus("10");
view.setClaimType("2");
view.setAdjustAdditionalLaborTimes(null);
view.setSubmitDate("2020-01-12");
view.setApproveDate("2020-02-12");
view.setProductionDate("2020-03-12");
view.setPurchaseDate("2020-03-12");
view.setReceptionDate("2020-04-12");
view.setClaimNo("我是-订单号");
String ysj = JSON.toJSON(view).toString();
System.out.println(ysj);
String pat = "\\d{4}-\\d{2}-\\d{2}";
Pattern pattern = Pattern.compile(pat);
Matcher matcher = pattern.matcher(ysj);
List<String> stringList = new ArrayList<>();
while(matcher.find()){
stringList.add(matcher.group());
}
for (String s : stringList) {
if (ysj.contains(s)){
ysj = ysj.replace("Date\":\""+s,"Date\":\""+s.replace("-","/"));
}
}
WcmWarrantyClaimExportView wcmWarrantyClaimExportView = JSONObject.toJavaObject(JSON.parseObject(ysj), WcmWarrantyClaimExportView.class);
System.out.println(JSON.toJSON(wcmWarrantyClaimExportView).toString());
}
}

对象转JSON正则查找替换

标签:cas   app   package   export   cti   fas   UNC   mes   import   

原文地址:https://www.cnblogs.com/jabez1992/p/14024043.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!