7

I want to configure custom message converters based on endpoints. For example, I have below two endpoints in Spring boot controller:

@RequestMapping(value = "/all", method = RequestMethod.GET)
public ResponseEntity<Object> findAll{@PageableDefault(size = 10, page = 0) final Pageable pageable){
    //code
}
    
@RequestMapping(value = "/object/{id}", method = RequestMethod.GET)
public ResponseEntity<Object> byId{@RequestParam("id" String id){
    //code
}

For both of these, I want to use different HttpMessageConverter (and in turn, object mapper) instances. E.g. I want to set CAMEL_CASE_TO_LOWER_CASE_WITH_UNDERSCORES strategy for /all end point due to it being paged response but not for /object.

The application already has configureMessageConverters method overridden, with an Objectmapper bean used for all the apis. If I make any change to that, it will be applicable to all the endpoints which is something I don't want.

Is there any other way to do this? (Something like creating and using custom message converter in the findAll method itself)

EricSchaefer
  • 25,272
  • 21
  • 67
  • 103
Darshan Mehta
  • 30,102
  • 11
  • 68
  • 102
  • http://stackoverflow.com/users/1120793/darshan-mehta did you find a solution for this ? I just posted a question similar to what you asked. http://stackoverflow.com/questions/42219676/how-to-apply-spring-message-convertors-based-on-condition – Pramod Feb 14 '17 at 06:57

0 Answers0