I'm trying to understand a warning in my Spring code.
I have a HttpEntity which is being set to my HttpHeaders, however its getting flagged as a Raw use of the class.
I'm not sure why this is, nor, how to rectify the warning. I know it's only a warning but I'd like to get rid of this.
Can someone shed some light on the why and the how to remove it.
final HttpHeaders headers = new HttpHeaders();
final HttpEntity entity = new HttpEntity(headers);
private final static Logger logger = LoggerFactory.getLogger(GitHubService.class);
@Autowired
public GitHubService() {
headers.set("Authorization", gitHubAuthToken);
headers.set("Accept", "application/vnd.github.VERSION.raw");
}
I'm also getting the same type of warning
Warning:(44, 35) Unchecked call to 'HttpEntity(MultiValueMap<String, String>)' as a member of raw type 'org.springframework.http.HttpEntity'
Many thanks
CodePudding user response:
You just need to add the parameterized type:
final HttpEntity<String> entity = new HttyEntity<>(headers);
The type is the body of the entity. Probably a string, but depends on how you use it.