【发布时间】:2020-05-21 16:34:25
【问题描述】:
我需要将 json 转换为 pojo 我已经有使用它的服务但我想把它带到一个 POJO 以便能够处理它
这都是 Json:
{
"meta": {
"status": "success",
"version": "2.0"
},
"data": {
"id": "M!t!Ch!v1!0000100002-5gda5bq0059b1-1245432868",
"token": "d71b160d82dfeeca87aa580f526d8570",
"privileges": {
"__GLOBAL__": {
"Store": {
"1-m!i!s-045-158": {
"*": -1
},
"1-m!i!s-047-324": {
"*": -1
},
"1-m!i!s-031-1491": {
"*": -1
},
"1-m!i!s-046-2": {
"*": -1
}
}
}
},
"data": {
"accessorId": 100001
}
}
}
这部分所有的键都是动态的:
"1-m!i!s-045-158":{"*":-1} // **the key: 1-m!i!s-045-158 is dinamic**
{"1-m!i!s-045-158":{"*":-1},"1-m!i!s-047-324":{"*":-1},"1-m!i!s-031-1491":{"*":-1},"1-m!i!s-046-2":{"*":-1}}
这是我的控制器
public JsonNode Evento(JsonNode json) {
HttpHeaders header = new HttpHeaders();
//header.add("Content-Type", "application/json");
RestTemplate template = new RestTemplate();
JsonNode node = mapper.convertValue(json , JsonNode.class);
HttpEntity<?> request = new HttpEntity<>(node);
JsonNode resultado = template.postForObject("http://localhost:8083/moddo-channels/api/miinto", request, JsonNode.class);
System.out.println(json.findPath("stote"));
System.out.println(resultado);
return json;
}
【问题讨论】:
标签: java json spring-boot