In a Spring Boot application, you are required to develop a feature where the response body should be customized based on the client's preference. How would you implement this feature using Spring Boot annotations?

  • Use the @ResponseBody annotation on controller methods and generate custom responses based on client preference in each method.
  • Implement content negotiation with @RequestMapping annotations to handle client preferences automatically.
  • Use the @RequestParam annotation to pass the client's preference as a parameter to controller methods and customize the response accordingly.
  • Define a custom response handler class and annotate it with @RestControllerAdvice to handle client preferences for all controllers.
To implement a feature in a Spring Boot application where the response body is customized based on client preference, you should use content negotiation with @RequestMapping annotations. This allows Spring Boot to handle client preferences automatically. Option 2 is the recommended approach as it promotes clean and efficient code. The other options may require more manual coding and could be less maintainable.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *