Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
This repository was archived by the owner on Feb 26, 2023. It is now read-only.
This repository was archived by the owner on Feb 26, 2023. It is now read-only.

Spring Rest Template 2.x Support #1253

Copy link
Copy link
@vincentjames501

Description

@vincentjames501
Issue body actions

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:

  1. 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
  1. 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

Reactions are currently unavailable

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.