我无法从katable到pojo类输出中获取数据
我试图称呼汇合的卡夫卡的其余端点,但我有能力将输出结果放在pojo类中。
@PostMapping("/QueryForEquipment")
@Consumes("application/json")
public String getEquipments() {
String walletBalanceUrl = "http://172.21.79.18:8088/query";
HttpHeaders httpHeaders = new HttpHeaders();
httpHeaders.set("Content-Type", "application/json");
httpHeaders.add("Accept", MediaType.APPLICATION_JSON.toString());
JSONObject json = new JSONObject();
json.put("ksql", "Select * from EQP_STREAM limit 10;");
JSONObject jsonSub = new JSONObject();
jsonSub.put("ksql.streams.auto.offset.reset", "earliest");
json.put("streamsProperties", jsonSub);
/* String body=new String("{
"ksql": "Select ROWTIME,ROWKEY,TRN_ID_KEY from TABLE_EQP_LOCATION limit 10;",
"streamsProperties": {"ksql.streams.auto.offset.reset": "earliest"} }");
*/
System.out.println(walletBalanceUrl);
HttpEntity httpEntity = new HttpEntity(body, httpHeaders);
RestTemplate restTemplate = new RestTemplate();
System.out.println("json text====" + body);
ResponseEntity<String> uri = restTemplate.postForEntity(walletBalanceUrl, httpEntity, String.class);
return uri.getBody().toString();
预期输出必须为json格式 目前以
{"row":{"columns":[1556458915675,"CDAU603054","Q1214320190418","TRAIN","Arrived","BELLEVILLE","Q","1214","4",1555545600000," ",1555618200000,"SRS_TRAIN","-77.374856","44.179657",null,null,"CDAU603054","CDAU","603054","INTERMODAL","L","KC7","7","DTTX720029","DTTX","720029","C","T","TOP",1555621693617]},"errorMessage":null,"finalMessage":null}
{"row":{"columns":[1556458915680,"CDAU603066","Q1214320190418","TRAIN","Arrived","BELLEVILLE","Q","1214","4",1555545600000," ",1555618200000,"SRS_TRAIN","-77.374856","44.179657",null,null,"CDAU603066","CDAU","603066","INTERMODAL","L","KC7","8","DTTX720030","DTTX","720030","D","T","TOP",1555621693617]},"errorMessage":null,"finalMessage":null}
{"row":{"columns":[1556458915680,"CDAU603070","Q1214320190418","TRAIN","Arrived","BELLEVILLE","Q","1214","4",1555545600000," ",1555618200000,"SRS_TRAIN","-77.374856","44.179657",null,null,"CDAU603070","CDAU","603070","INTERMODAL","L","KC7","8","DTTX720030","DTTX","720030","A","T","TOP",1555621693617]},"errorMessage":null,"finalMessage":null}
答案 0 :(得分:0)
此处, 内容类型 将是 application / vnd.ksql.v1 + json 并进行设置 字符集 到 utf-8 。
HttpHeaders headers = new HttpHeaders();
headers.set("Content-Type", "application/vnd.ksql.v1+json");
headers.set("charset", "utf-8");
headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
并且ksql查询将是 SELECT * from EQP_STREAM EMIT CHANGES limit 10;
json.put("ksql", "SELECT * from EQP_STREAM EMIT CHANGES limit 10;")
作为参考,请检查以下链接: https://docs.ksqldb.io/en/latest/developer-guide/ksqldb-rest-api/ksql-endpoint/