Estou recebendo esta exceção ao usar o TestRestTemplate
:
org.springframework.web.client.RestClientException: Error while extracting response for type [java.util.List<me.heenluy.travels.app.Travel>] and content type [application/json]; nested exception is org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Cannot deserialize value of type
java.util.ArrayList<me.heenluy.travels.app.Travel>
from Object value (tokenJsonToken.START_OBJECT
); nested exception is com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize value of typejava.util.ArrayList<me.heenluy.travels.app.Travel>
from Object value (tokenJsonToken.START_OBJECT
) at [Source: (PushbackInputStream); line: 1, column: 1]
Meu código:
@Autowired
TestRestTemplate restTemplate;
ResponseEntity<List<Travel>> response = restTemplate.withBasicAuth(user, password)
.exchange(url, HttpMethod.GET, null, new ParameterizedTypeReference<>() {});
Controller:
@GetMapping(
path = "travels/get/principal/list",
produces = MediaType.APPLICATION_JSON_VALUE
)
public ResponseEntity<List<Travel>> getListByActiveUser(@AuthenticationPrincipal AppUser user) {
List<Travel> travels = travelService.getListByUserFromRepository(user.getEmail());
ResponseEntity<List<Travel>> response = new ResponseEntity<>(travels, HttpStatus.OK);
return response;
}
Por algum motivo, quando faço a requisição pelo curl, Httpie ou RestTemplate (sem o 'Test') funciona normalmente.
Alguém pode me ajudar?