I have a Java SpringBoot backend server and I wanted to test the controller classes with curl. However, whenever I send a request with the following format (in a powershell terminal):
curl --request POST --header "Content-Type: application/json" --data '{\"key\": 5}' http://localhost:8080/request
All the numerical values are changed to zeroes. And if in the DTO class I change them to Integer
instead of int
, then they are received as null
. For strings, everything works perfectly.
This is what my controller methodlooks like:
@RestController
@RequestMapping("/request")
class MyController {
@PostMapping
public ResponseEntity<MuseumTO> createMuseum(@RequestBody RequestDTO request) {
System.out.println(request.key);
// ...
}
}
And the DTO class:
class RequestDTO {
public int key
}
GET requests work fine, and I've tried with two different backends, so I assume my problem is coming from the curl request's format. However, I've looked online and from what I've seen this is supposed to work.