use of com.alibaba.fastjson2.JSONArray 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.JSONArray in project SpringBoot-Hello by ruiyeclub.
the class FastJson2ApplicationTests method testParseArray.
/**
* JSON字符串转换成数组
*/
@Test
public void testParseArray() {
String str = "[\"id\", 123]";
JSONArray objects = JSON.parseArray(str);
String idStr = objects.getString(0);
System.out.println(idStr);
}
use of com.alibaba.fastjson2.JSONArray 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.JSONArray in project druid by alibaba.
the class MySqlParameterizedOutputVisitorTest_43 method restore.
public static String restore(String sql, String table, String params) /*JSONArray paramsArray, JSONArray destArray*/
{
JSONArray destArray = JSON.parseArray(table.replaceAll("''", "'"));
params = StringUtils.replace(params.replaceAll("''", "'"), "\\\"", "\"");
JSONArray paramsArray = JSON.parseArray(params);
DbType dbType = JdbcConstants.MYSQL;
List<SQLStatement> stmtList = SQLUtils.parseStatements(sql, dbType);
SQLStatement stmt = stmtList.get(0);
StringBuilder out = new StringBuilder();
SQLASTOutputVisitor visitor = SQLUtils.createOutputVisitor(out, dbType);
List<Object> paramsList = new ArrayList<Object>(paramsArray);
visitor.setParameters(paramsList);
SchemaStatVisitor schemaStatVisitor = new MySqlSchemaStatVisitor();
stmt.accept(schemaStatVisitor);
JSONArray srcArray = new JSONArray();
for (Map.Entry<TableStat.Name, TableStat> entry : schemaStatVisitor.getTables().entrySet()) {
System.out.println(entry.getKey().getName());
srcArray.add(entry.getKey().getName());
}
for (int i = 0; i < srcArray.size(); i++) {
visitor.addTableMapping(srcArray.getString(i), destArray.getString(i));
}
stmt.accept(visitor);
return out.toString();
}
use of com.alibaba.fastjson2.JSONArray in project druid by alibaba.
the class MySqlParameterizedOutputVisitorTest_44 method test_for_parameterize.
public void test_for_parameterize() throws Exception {
final DbType dbType = JdbcConstants.MYSQL;
String sql = "select 1 from a where c1 in (date_format(date_add(curdate(), INTERVAL -7 DAY), '%Y%m%d'))";
SQLStatementParser parser = SQLParserUtils.createSQLStatementParser(sql, dbType);
List<SQLStatement> stmtList = parser.parseStatementList();
SQLStatement statement = stmtList.get(0);
StringBuilder out = new StringBuilder();
SQLASTOutputVisitor visitor = SQLUtils.createOutputVisitor(out, JdbcConstants.MYSQL);
List<Object> parameters = new ArrayList<Object>();
visitor.setParameterized(true);
visitor.setParameterizedMergeInList(true);
visitor.setParameters(parameters);
/*visitor.setPrettyFormat(false);*/
statement.accept(visitor);
/* JSONArray array = new JSONArray();
for(String table : visitor.getTables()){
array.add(table.replaceAll("`",""));
}*/
String psql = out.toString();
System.out.println(psql);
assertEquals("SELECT ?\n" + "FROM a\n" + "WHERE c1 IN (date_format(date_add(curdate(), INTERVAL ? DAY), '%Y%m%d'))", psql);
String params_json = JSON.toJSONString(parameters, JSONWriter.Feature.WriteClassName);
System.out.println(params_json);
JSONArray jsonArray = JSON.parseArray(params_json);
String json = JSON.toJSONString(jsonArray, JSONWriter.Feature.WriteClassName);
assertEquals("[1,-7]", json);
String rsql = SQLUtils.toSQLString(SQLUtils.parseStatements(psql, dbType), dbType, jsonArray);
assertEquals("SELECT 1\n" + "FROM a\n" + "WHERE c1 IN (date_format(date_add(curdate(), INTERVAL -7 DAY), '%Y%m%d'))", rsql);
}
Aggregations