ARTICLE AD BOX
I’m building a Spring Boot REST API and I’m stuck on an issue that I can’t figure out.
I have a simple POST endpoint that should receive a JSON payload and map it to a DTO, but every time I call the endpoint the request body is null. The controller is called successfully, but the DTO fields are all null, and sometimes I get a 400 Bad Request.
@RestController @RequestMapping("/api/products") public class ProductController { @PostMapping public ResponseEntity<String> createProduct(@RequestBody ProductRequest productRequest) { System.out.println("DEBUG => " + productRequest); return ResponseEntity.ok("Received"); } } @Data public class ProductRequest { private String name; private Double price; }Why is the @RequestBody not binding the JSON to my DTO? What could cause the request body to always be null in Spring Boot even with valid JSON?
