'Postman Get call 500 internal server error
Having some trouble here with this GET endpoint. For some reason is calling status 500 Internal Server Error and the body comes as null.
This is the code with the GET call:
@GetMapping
public List<TitulosPagar> getTitulosPagar() {
System.out.println("GET called");
List<TitulosPagar> titulos = titulosPagarService.pesquisar();
System.out.println(titulos);
return titulos;
titulosPagarService.pesquisar() return a JpaRepository.findAll() with the a full list of titulosPagar.
The sysoutPrint shows that it gets the list made with the objects TitulosPagar:
GET called
[br.com.lev.ficpagar.model.TitulosPagar@13d10944, br.com.lev.ficpagar.model.TitulosPagar@5a57aa65,
br.com.lev.ficpagar.model.TitulosPagar@1ac0f72, br.com.lev.ficpagar.model.TitulosPagar@3a052abc]
But in Postman I got a null body and the 500 Internal Server Error
Postman Console response:
GET /ficpagar/titulospagar HTTP/1.1
Content-Type: application/json
User-Agent: PostmanRuntime/7.24.1
Accept: */*
Cache-Control: no-cache
Postman-Token: b273167d-92d4-44e6-bea0-88c8b70af99e
Host: localhost:8080
Accept-Encoding: gzip, deflate, be
Connection: keep-alive
HTTP/1.1 500 Internal Server Error
Access-Control-Allow-Origin: http://localhost:4200
Access-Control-Allow-Credentials: true
Content-Type: application/json
Transfer-Encoding: chunked
Date: Tue, 14 Apr 2020 20:31:03 GMT
Connection: close
,
curl --location --request GET 'localhost:8080/ficpagar/titulospagar' \
--header 'Content-Type: application/json' \
--data-raw ''
The weird thing is that works fine this test GET endpoint.
@GetMapping
public String test() {
return "Everything fine!";
}
And the POST endpoint:
@PostMapping
public ResponseEntity<TitulosPagar> criar(@Valid @RequestBody TitulosPagar tituloPagar, HttpServletResponse response) {
tituloPagar = titulosPagarService.criar(tituloPagar);
URI uri = ServletUriComponentsBuilder.fromCurrentRequestUri().path("/{codigo}").buildAndExpand(tituloPagar.getId()).toUri();
response.setHeader("Location", uri.toASCIIString());
return ResponseEntity.created(uri).body(tituloPagar);
}
I use a localServer with PostgreSQL.
It doesnt seem to be a problem in the code. But I dont know, do you understand what could be wrong?
Solution 1:[1]
I got it! The problem was that when getting the attributes to show in the postman, it entered in a loop for the objects that reference other objects. To resolve I had to eliminate the recurring Get(), or just get the id from the object
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Gjomesquita |
