im working ina spring project and using restemplate to call POST API that take a List of DTOOne And return a List of DTOTWO.
this is my code :
List<MYDTOONE> listDTORequest;
//values..
ResponseEntity<List<MYDTOOTWO>> userActionsResponse = restTemplate.postForEntity("my yrl",
listDTORequest, MYDTOOTWO.class);
im geeting a Syntax error in the last param i need to know how i can tell postForEntity that im waiting for List.
i tried also List<MYDTOOTWO> in the last paramater but still syntax error
thanks in advance.
>Solution :
It may not be the cleanest code, but it is the fastest and simplest way I have found to do it. You read it as an Array and then put it in the List.
List<MYDTOONE> listDTORequest;
// JDK8
List<MYDTOOTWO> userActionsResponse = Arrays.asList(restTemplate.postForEntity("my url", listDTORequest, MYDTOOTWO[].class).getBody());
// JDK9+
List<MYDTOOTWO> userActionsResponse = List.of(restTemplate.postForEntity("my url", listDTORequest, MYDTOOTWO[].class).getBody());