Using dependency
compile 'org.springframework.android:spring-android-rest-template:2.0.0.M1'
Calls to restTemplate.exchange(...) in 2.x will create an ambiguous method call when the response class is null. Here are the two conflicting method signatures (the second one was added in 2.x).
<T> ResponseEntity<T> exchange(String url, HttpMethod method, HttpEntity<?> requestEntity,
Class<T> responseType, Object... uriVariables) throws RestClientException
<T> ResponseEntity<T> exchange(String url,HttpMethod method, HttpEntity<?> requestEntity,
ParameterizedTypeReference<T> responseType, Object... uriVariables) throws RestClientException
My proposal would be to use one of the following:
- Instead of using
exchange(...) for each method call, use the appropriate method depending on the known HttpMethod.
//For DELETE
restTemplate.delete(rootUrl.concat(""), urlVariables);
//For GET
restTemplate.getForEntity(rootUrl.concat(""), MyClass.class, urlVariables);
//For POST
restTemplate.postForEntity(rootUrl.concat(""), requestEntity, MyClass.class, urlVariables);
//For PUT
restTemplate.putForEntity(rootUrl.concat(""), requestEntity, MyClass.class, urlVariables);
//For Options
restTemplate.optionsForAllow(rootUrl.concat(""), urlVariables);
//Etc
- When the response class is null, cast it like below (this simply avoid the ambiguous arguments):
@Override
public void deleteResourceById(String id) {
{
HashMap<String, Object> urlVariables = new HashMap<String, Object>();
urlVariables.put("id", id);
//Note the cast on 'null'
restTemplate.exchange(rootUrl.concat("/resources/{id}"), HttpMethod.DELETE, null, (Class<Object>)null, urlVariables);
}
}
Option 2 is obviously the simplest. I'd be happy to do the pull request, just looking for some input on what people feel is the best approach.
Vince
Using dependency
compile 'org.springframework.android:spring-android-rest-template:2.0.0.M1'Calls to
restTemplate.exchange(...)in 2.x will create an ambiguous method call when the response class isnull. Here are the two conflicting method signatures (the second one was added in 2.x).My proposal would be to use one of the following:
exchange(...)for each method call, use the appropriate method depending on the knownHttpMethod.Option 2 is obviously the simplest. I'd be happy to do the pull request, just looking for some input on what people feel is the best approach.
Vince