一开始code
columnList.forEach(column -> { if (map.containsKey(column) && map.get(column) != null) { Object obj = map.get(column); if (obj instanceof ArrayList) { JSONArray jsonArray = new JSONArray((ArrayList) obj); List<Integer> list = new ArrayList<>(); for (Object o : jsonArray) { if (!(o instanceof CmdbUserResp)) { break; } JSONObject jsonObject = (JSONObject) JSON.toJSON(o); list.add(jsonObject.getInteger("id")); } if (CollUtil.isNotEmpty(list)) { obj = list; } } String value = JSON.toJSONString(obj); map.put(column, value); } });
修改后
columnList.forEach(column -> { if (map.containsKey(column) && map.get(column) != null) { Object obj = map.get(column); if (obj instanceof ArrayList) { List<CmdbUserResp> cmdbUserResps = (List<CmdbUserResp>) obj; obj = cmdbUserResps.stream().map(e -> e.getId()).collect(Collectors.toList()); } String value = JSON.toJSONString(obj); map.put(column, value); } });