I want to implement Spring endpoint in which I can return XML object NotificationEchoResponse
and http status code. I tried this:
@PostMapping(value = "/v1/notification", produces = "application/xml")
public ResponseEntity<?> handleNotifications(@RequestParam MultiValueMap<String, Object> keyValuePairs) {
if (!tnx_sirnature.equals(signature))
{
return new ResponseEntity<>("Please contact technical support!", HttpStatus.INTERNAL_SERVER_ERROR);
}
return new ResponseEntity<>(new NotificationEchoResponse(unique_id), HttpStatus.OK);
}
But I get error: Cannot infer type arguments for ResponseEntity<>
at this line: return new ResponseEntity<>("Please contact technical support!", HttpStatus.INTERNAL_SERVER_ERROR);
Do you know know how I can fix this issue?
ResponseEntity.ok(value)
. Additionally, it's more conventional to throw an exception in the first case and gave a global exception handler build error responses for consistency. – PyretotherapyControllerAdvice
so google that. Just wanted to say your method is returning aResponseEntity<?>
With means a response type containing "any" type. When you declare your responses you set the diamond operator to<>
nothing. You are basically telling to compiler to figure out the return type but it can't so you getCannot infer type arguments for ResponseEntity<>
. Why can't it figure it out, well the compiler will look at the method return type to figure it out but you have declared it to be any type. So the compiler cant guess. – AirtightResponseEntity<String>
andResponseEntity< NotificationEchoResponse>
but this is an ugly solution. – Airtight