Если вы хотите преобразовать JSON в хэш-карту в controller
, то решение подойдет ниже. ObjectConvetore reduce your performance. It's an extra conversion
.
@ResponseStatus(HttpStatus.ACCEPTED)
@RequestMapping(value = "/hi", method = RequestMethod.POST, consumes = "application/json")
public void startMartExecution(@RequestBody(required = true) Map<String,String> martCriterias) {
System.out.println(martCriterias.get("name"));
}
Если вы позвоните restAPI from your application
, то код ниже будет работать.
HttpHeaders headers = new HttpHeaders();
RestTemplate restTemplate = new RestTemplate();
headers.setContentType(MediaType.APPLICATION_JSON);
headers.setAccept(Collections.singletonList(MediaType.ALL));
HttpEntity<Void> entity = new HttpEntity<Void>(null, headers);
Map<String, Object> body = new HashMap<>();
ParameterizedTypeReference<Map<String, Object>> parameterizedTypeReference = new ParameterizedTypeReference<Map<String, Object>>() {};
ResponseEntity<Map<String, Object>> result = restTemplate.exchange(URL, HttpMethod.GET, entity, parameterizedTypeReference);
body = result.getBody();
Спасибо