Spring WebFlux. How to get the request body in two different formats using @RequestBody annotation?
Having multiple @RequestBody
is not possible. If you really need both original JSON and its serialized version the best you can do is receive the request body as a plain String
and then convert it to the corresponding Java object as follows:
@Autowired
private ObjectMapper objectMapper;
@PostMapping("/play")
public Mono<PlayResponse> play(@RequestBody String body){
PlayCommand playCommand = objectMapper.readValue(body, PlayCommand.class);
}