I'm using Spring Boot @RequestBody annotation to access the request body properties like below
@PostMapping ResponseEntity<UserDto> createUser (@RequestBody UserDto userDto) { // some coode return null; } What I want to do is instead of just accessing the userDto properties. I want to log the whole request body because someone else is using sending the request and it doesn't match my userDto
What I tried?
@PostMapping ResponseEntity<UserDto> createUser (HttpServletRequest request) { logger.info("Body: {}", request.getReader().lines().collect(Collectors.toSet())); return null; } This works just fine but each time I want to log the request body I have to switch between @RequestBody UserDto and HttpServletRequest request
Is there anyway I can keep that jackson @RequestBody annonation and still log request body as it is?
toStringmethod forUserDto?