Skip to content
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

Closed

Description

@vincentjames501

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

Activity

  1. dodgex commented on Nov 19, 2014

    @dodgex
    Member

    currently 2.0 is not supported. there is already another issue and also a PR.

  2. WonderCsabo commented on Nov 19, 2014

    @WonderCsabo
    Member

    Thanks for the detailed bug report! I am closing this issue in favor of the other one.
    Please note that @royclarkson seems rather busy, and could not finish the PR. So i think he would not mind if you pick it up!

  3. WonderCsabo commented on Nov 19, 2014

    @WonderCsabo
    Member

    @royclarkson just indicated he will return to the work of that PR after the release of the next milestone of the upstream Spring project.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions