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)