ResponseBody
We use @ResponseBody
to convert the response into JSON automatically.
For example
@PostMapping(value = "/v{version}/meow", produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public Callable<ResponseEntity<MeowRequest>> greet(@PathVariable String version,
@RequestBody @Valid MeowRequest request) {
return () -> ResponseEntity.ok(request);
}
This will automatically convert object MeowRequest
to json form.
For example in here our MeowRequest
is
@Setter
@Getter
public class MeowRequest {
@NotNull
private Animal type;
}
Will return
{
"type": "CAT"
}