fastjson妙用
fastjson在java开发中有妙用
public List<DmTableWithDomainPath> DmTables2DmTableWithDomainPaths(List<DmTable> tables){ List<DmTableWithDomainPath> dmTableWithDomainPaths = new ArrayList<>(); tables.forEach(table->{
// java对象转换成json对象 JSONObject tableJSONObject = (JSONObject) JSON.toJSON(table); int domainID= table.getDomainId(); if (domainID!=0){ DmDomain dmDomain = dmDomainServiceImpl.queryInfoByNatrualKey(domainID); if (dmDomain!=null) {
// json对象添加键值对 tableJSONObject.put("paths", dmDomain.getPaths()); }
// json对象转换成json字符串 String tableStr= JSON.toJSONString(tableJSONObject);
// json字符串转换成另一个java对象 DmTableWithDomainPath dmTableWithDomainPath =JSON.parseObject(tableStr,DmTableWithDomainPath.class);
dmTableWithDomainPaths.add(dmTableWithDomainPath); } }); return dmTableWithDomainPaths; }