I need to convert multiple request headers (not a single one) in to custom object in Spring. I tried it out using custom converter
public class HeadersMapToCustomObjectConverter implements Converter<Map<String,String>, CustomObject>
{
@Override
public CustomObject convert(Map<String, String> source) {
return new CustomObject(source);
}
}
and Controller method signature:
@PostMapping(value = "/content", consumes = {MediaType.MULTIPART_FORM_DATA_VALUE})
public ResponseEntity<MyResponse> process(
HttpServletRequest request,
@RequestHeader CustomObject customObject)
which results in error
Unhandled exception:
org.springframework.web.bind.MissingRequestHeaderException: Required request header 'customObject' for method parameter type CustomObject is not present
at org.springframework.web.method.annotation.RequestHeaderMethodArgumentResolver.handleMissingValue(RequestHeaderMethodArgumentResolver.java:87)
@RequestHeader annotation requires Map<String, String> parameter type to catch all headers, but it breaks implicit conversion.