I try to write custom HttpMessageConverter for RESTful API but the converter is not being called at all.
Here is my controller code:
@RequestMapping(value = "/devices/statuses/{serial}", method=RequestMethod.GET,produces = "application/json;charset=UTF-8")
public ResponseEntity<List<DeviceStatus>> getDeviceStatuses(@PathVariable(value="serial") String serial,
@RequestParam("from") long from,
@RequestParam("to") long to) {
List<DeviceStatus> statuses = systemFacade.getDeviceStatuses(serial, new DateTime(from), new DateTime(to));
return new ResponseEntity<List<DeviceStatus>>(statuses,HttpStatus.OK);
}
Custom HttpMessageConverter (the methods are empty to show only how it is configured):
public class HosHttpMessageConverter extends AbstractHttpMessageConverter<Object>{
public HosHttpMessageConverter() {
super(MediaType.APPLICATION_JSON_UTF8);
}
@Override
protected boolean supports(Class<?> arg0) {
return true;
}
@Override
protected Object readInternal(Class<? extends Object> clazz, HttpInputMessage message)
throws IOException, HttpMessageNotReadableException {
// TODO Auto-generated method stub
return null;
}
@Override
protected void writeInternal(Object object, HttpOutputMessage message)
throws IOException, HttpMessageNotWritableException {
// TODO Auto-generated method stub
}
}
Converter registrations:
@EnableWebMvc
@Configuration
public class WebMvcConfig extends WebMvcConfigurerAdapter {
@Override
public void extendMessageConverters(List<HttpMessageConverter<?>> converters) {
converters.add(new HosHttpMessageConverter());
}
}
Any suggestion what can be the reason why my custom converter not working? Thanks for any suggestions!