I have a simple APIs that initiates some action on records and return a 200 response:
/**
* Initiate some workflow.
*
* @param recordsBulkInitiate records to initiate
* @return {@link ResponseEntity}
*/
@ApiOperation(value = "initiate workflow")
@PostMapping("/initiate")
public ResponseEntity bulkInitiateRecords(@RequestBody InitiateBulkRecordsDto recordsBulkInitiate) {
workflowService.bulkInitiate(recordsBulkInitiate);
return ResponseEntity.ok(OK);
}
/**
* Submit some workflow action on arecord
*
* @param workflowActionDto the record action data
* @return {@link ResponseEntity}
*/
@ApiOperation(value = "action taken by user")
@PostMapping("/action")
public ResponseEntity submitAction(@RequestBody WorkflowActionDto workflowActionDto) {
log.info("submit action on record [{}]", workflowActionDto);
workflowService.submitRecordAction(workflowActionDto);
return ResponseEntity.ok(OK);
}
Both Sonarlint and intellij throws warnings: "Raw types should not be used".
How should I handle this warning? For now, I'm just using ResponseEntity<Object>
which seems like a hack.
You can replace ResponseEntity<?>
instead of ResponseEntity
on your method signature return type:
public ResponseEntity<?> submitAction(@RequestBody WorkflowActionDto workflowActionDto)
You can avoid IDE warnings, but they are actually the same, compiler would replace it with generic type, so ResponseEntity<?>
and ResponseEntity
are the same.
EDIT:
As I see you are returning ResponseEntity.ok(HttpStatus.OK)
, so you are returning a body of type HttpStatus
. So you can be more explicit in your methode signature by using ReponseEntity<HttpStatus>
.