I am writing a web service. I use @RestController . For example, there is a method that returns the user by id:

 @RequestMapping(value = "/{id}", method = RequestMethod.GET) public ResponseEntity userById(@PathVariable("id") Long id) { return new ResponseEntity(entityConverter.userToDTO(userService.getById(id)), HttpStatus.OK); } 

I use Intellij Idea. This method works as it should, but the IDE writes a warning:

Warning: (35, 28) Unchecked call to 'ResponseEntity (T, HttpStatus)' as a member of raw type 'org.springframework.http.ResponseEntity'

How to handle it correctly?

    1 answer 1

    Specify a generic type for the returned ResponseEntity:

     @RequestMapping(value = "/{id}", method = RequestMethod.GET) public ResponseEntity<String> userById(@PathVariable("id") Long id) { return new ResponseEntity<String>(new String("test"), HttpStatus.OK); } 

    In your case, instead of a String, there will be a certain UserDTO.

    • one
      Thank. Warnings are gone. You can simply write new ResponseEntity<> - MrGarison
    • one
      Well, yes, from the seventh version of Java, you can simply new ResponseEntity <> - Ro1