fastjson在java開發中有妙用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; }