Announcement Announcement Module
Collapse
No announcement yet.
RestTemplate and generics Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • RestTemplate and generics

    This issue was resolved in Spring 3.2 https://jira.springsource.org/browse/SPR-7023 but it wasn't ported to spring for android. To clarify, it isn't possibile to do something like this at the moment using the version of RestTemplate in spring for android

    Code:
    ResponseEntity<MyWrapper<SomeType>> response = restTemplate.exchange(...)
    It's possible in Spring 3.2

    Code:
    public <T> ResponseEntity<T> exchange(String url, HttpMethod method, HttpEntity<?> requestEntity,
    			ParameterizedTypeReference<T> responseType, Map<String, ?> uriVariables) throws RestClientException {
    
    		Type type = responseType.getType();
    		HttpEntityRequestCallback requestCallback = new HttpEntityRequestCallback(requestEntity, type);
    		ResponseEntityResponseExtractor<T> responseExtractor = new ResponseEntityResponseExtractor<T>(type);
    		return execute(url, method, requestCallback, responseExtractor, uriVariables);
    	}
    Is it possible to port the Spring 3.2 code as is to Android? or if not, what workaround could I use?
    Last edited by alexmaz; Feb 1st, 2013, 09:43 AM.

  • #2
    Well, I found this https://jira.springsource.org/browse/ANDROID-122

    Trying to do the same for a quick fix but I'm getting a java.lang.NoClassDefFoundError which I'm unable to track

    Comment


    • #3
      I'm getting NoClassDefFoundException on RestTemplate even compiling the original source from github, what could be the problem?

      Code:
      02-01 22:55:20.453: E/AndroidRuntime(25733): FATAL EXCEPTION: main
      02-01 22:55:20.453: E/AndroidRuntime(25733): java.lang.NoClassDefFoundError: org.springframework.web.client.RestTemplate
      02-01 22:55:20.453: E/AndroidRuntime(25733): 	at com.prismio.pois.android.rest.RestService.<init>(RestService.java:32)
      02-01 22:55:20.453: E/AndroidRuntime(25733): 	at java.lang.Class.newInstanceImpl(Native Method)
      02-01 22:55:20.453: E/AndroidRuntime(25733): 	at java.lang.Class.newInstance(Class.java:1319)
      02-01 22:55:20.453: E/AndroidRuntime(25733): 	at android.app.ActivityThread.handleCreateService(ActivityThread.java:2470)
      02-01 22:55:20.453: E/AndroidRuntime(25733): 	at android.app.ActivityThread.access$1600(ActivityThread.java:142)
      02-01 22:55:20.453: E/AndroidRuntime(25733): 	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1290)
      02-01 22:55:20.453: E/AndroidRuntime(25733): 	at android.os.Handler.dispatchMessage(Handler.java:99)
      02-01 22:55:20.453: E/AndroidRuntime(25733): 	at android.os.Looper.loop(Looper.java:137)
      02-01 22:55:20.453: E/AndroidRuntime(25733): 	at android.app.ActivityThread.main(ActivityThread.java:4931)
      02-01 22:55:20.453: E/AndroidRuntime(25733): 	at java.lang.reflect.Method.invokeNative(Native Method)
      02-01 22:55:20.453: E/AndroidRuntime(25733): 	at java.lang.reflect.Method.invoke(Method.java:511)
      02-01 22:55:20.453: E/AndroidRuntime(25733): 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
      02-01 22:55:20.453: E/AndroidRuntime(25733): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:558)
      02-01 22:55:20.453: E/AndroidRuntime(25733): 	at dalvik.system.NativeStart.main(Native Method)
      The jars I downloaded work fine
      Last edited by alexmaz; Feb 1st, 2013, 04:50 PM.

      Comment


      • #4
        The problem on build from stock source was because of java 7

        Comment


        • #5
          @alexmaz hi, I'm working on merging the generics support from Spring 3.2 into Spring for Android. I see you found the open JIRA for the issue. This fix along with other many other updates from 3.2 will be available in the upcoming 1.1.0.M1.

          Re. java. Yes, I'm working on a mac and have experienced the same issue with Java 7. Because of this, I'm continuing to use the Apple provided Java 6 for building the library locally.

          Comment


          • #6
            Thanks for your answer and for your work! I've ported some of the changes from 3.2 myself just to have something working quickly for my use case at the moment, which involves only MappingJackson2HttpMessageConverter. Working fine at the moment.

            Comment


            • #7
              Ok, great! good to know. Unfortunately, because Spring for Android is a fork of sorts from Spring Framework, it can be pretty tedious going through all the updates and merging in the applicable changes. I could short cut this process, but I like to keep everything in sync where possible. And that includes all the tests, which can be the most challenging.

              Comment

              Working...
              X