use of com.alibaba.fastjson2.JSONObject in project canal by alibaba.
the class DescribeBackupPolicyRequest method processResult.
@Override
protected RdsBackupPolicy processResult(HttpResponse response) throws Exception {
String result = EntityUtils.toString(response.getEntity());
JSONObject jsonObj = JSON.parseObject(result);
RdsBackupPolicy policy = new RdsBackupPolicy();
policy.setBackupRetentionPeriod(jsonObj.getString("BackupRetentionPeriod"));
policy.setBackupLog(jsonObj.getString("BackupLog").equalsIgnoreCase("Enable"));
policy.setLogBackupRetentionPeriod(jsonObj.getIntValue("LogBackupRetentionPeriod"));
policy.setPreferredBackupPeriod(jsonObj.getString("PreferredBackupPeriod"));
policy.setPreferredBackupTime(jsonObj.getString("PreferredBackupTime"));
return policy;
}
use of com.alibaba.fastjson2.JSONObject in project canal by alibaba.
the class CanalClusterController method clustersAndServers.
@GetMapping(value = "/clustersAndServers")
public BaseModel<List<?>> clustersAndServers(@PathVariable String env) {
List<CanalCluster> clusters = canalClusterServic.findList(new CanalCluster());
JSONObject group = new JSONObject();
group.put("label", "集群");
JSONArray jsonArray = new JSONArray();
clusters.forEach(cluster -> {
JSONObject item = new JSONObject();
item.put("label", cluster.getName());
item.put("value", "cluster:" + cluster.getId());
jsonArray.add(item);
});
group.put("options", jsonArray);
NodeServer param = new NodeServer();
param.setClusterId(-1L);
// 取所有standalone的节点
List<NodeServer> servers = nodeServerService.findAll(param);
JSONObject group2 = new JSONObject();
group2.put("label", "单机主机");
JSONArray jsonArray2 = new JSONArray();
servers.forEach(server -> {
JSONObject item = new JSONObject();
item.put("label", server.getName());
item.put("value", "server:" + server.getId());
jsonArray2.add(item);
});
group2.put("options", jsonArray2);
List<JSONObject> result = new ArrayList<>();
result.add(group);
result.add(group2);
return BaseModel.getInstance(result);
}
use of com.alibaba.fastjson2.JSONObject in project SpringBoot-Hello by ruiyeclub.
the class FastJson2ApplicationTests method testParseObject.
/**
* JSON字符串转换成对象
*/
@Test
public void testParseObject() {
String str = "{\"id\":123}";
JSONObject jsonObject = JSON.parseObject(str);
Integer id = jsonObject.getInteger("id");
System.out.println(id);
}
use of com.alibaba.fastjson2.JSONObject in project druid by alibaba.
the class MonitorStatService method getWebURIStatDataList.
@SuppressWarnings("unchecked")
private String getWebURIStatDataList(Map<String, String> parameters) {
Map<String, ServiceNode> allNodeMap = getServiceAllNodeMap(parameters);
List<Map<String, Object>> arrayMap = new ArrayList<>();
for (String nodeKey : allNodeMap.keySet()) {
ServiceNode serviceNode = allNodeMap.get(nodeKey);
String url = getRequestUrl(parameters, serviceNode, "/druid/weburi.json");
WebResult dataSourceResult = HttpUtil.get(url, WebResult.class);
if (dataSourceResult != null) {
List<WebResult.ContentBean> nodeContent = dataSourceResult.getContent();
if (nodeContent != null) {
for (WebResult.ContentBean contentBean : nodeContent) {
Map<String, Object> map = JSONObject.parseObject(JSONObject.toJSONString(contentBean), Map.class);
arrayMap.add(map);
}
}
}
}
List<Map<String, Object>> maps = comparatorOrderBy(arrayMap, parameters);
String jsonString = JSON.toJSONString(maps);
JSONArray objects = JSON.parseArray(jsonString);
JSONObject jsonObject = new JSONObject();
jsonObject.put("ResultCode", RESULT_CODE_SUCCESS);
jsonObject.put("Content", objects);
return jsonObject.toJSONString();
}
use of com.alibaba.fastjson2.JSONObject in project sakura-boot by yanjingfan.
the class ESTemplate method sendPostRequest.
public String sendPostRequest(String url, JSONObject params) {
RestTemplate client = new RestTemplate();
HttpHeaders headers = new HttpHeaders();
// 这里设置为APPLICATION_JSON
headers.setContentType(MediaType.APPLICATION_JSON);
// 将请求头部和参数合成一个请求
HttpEntity<JSONObject> requestEntity = new HttpEntity<>(params, headers);
// 执行POST请求
ResponseEntity<String> entity = client.postForEntity(url, requestEntity, String.class);
return entity.getBody();
}
Aggregations