2021年4月27日星期二

JAVA - Reflection onto Generic Type

i want do do a POST Request using Spring REST Template and a Generic Type for the ResponseEntity. For this i need to do a reflection onto the class i want to use for the ResponseEntity. How can i achieve this?

This is my code so far:

public <T> T post(String url, Map<String, Object> body) {      HttpHeaders headers = new HttpHeaders();      headers.setContentType(MediaType.APPLICATION_JSON);      headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));        //build Request      HttpEntity<Map<String, Object>> entity = new HttpEntity<>(body, headers);      //Send request      ResponseEntity<T> response = this.restTemplate.postForEntity(url, entity, T.class);  }  
https://stackoverflow.com/questions/67294597/java-reflection-onto-generic-type April 28, 2021 at 02:08PM

没有评论:

发表评论