Complete the code to specify the content type produced by the controller method.
@GetMapping(value = "/data", produces = "[1]") public String getData() { return "Hello"; }
The produces attribute defines the content type the method returns. Here, text/plain means plain text is sent.
Complete the code to accept JSON input in the controller method.
@PostMapping(value = "/submit", consumes = "[1]") public ResponseEntity<String> submitData(@RequestBody Data data) { return ResponseEntity.ok("Received"); }
text/plain instead of application/json.The consumes attribute specifies the content type the method accepts. For JSON input, use application/json.
Fix the error in the annotation to correctly produce XML content.
@GetMapping(value = "/info", produces = "[1]") public Info getInfo() { return new Info("data"); }
application/json when XML is expected.To produce XML output, the produces attribute must be set to application/xml.
Fill both blanks to accept JSON input and produce JSON output.
@PostMapping(value = "/process", consumes = "[1]", produces = "[2]") public ResponseEntity<String> process(@RequestBody Input input) { return ResponseEntity.ok("Done"); }
Both consumes and produces should be application/json to handle JSON input and output.
Fill all three blanks to create a controller method that accepts XML, produces JSON, and maps to "/convert".
@RequestMapping(value = "/[1]", consumes = "[2]", produces = "[3]") public ResponseEntity<String> convert(@RequestBody Data data) { return ResponseEntity.ok("Converted"); }
The method maps to /convert, consumes XML (application/xml), and produces JSON (application/json).