Results 1 to 7 of 7

Thread: RestTemplate and generics

  1. #1
    Join Date
    Dec 2011
    Posts
    10

    Default 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 at 09:43 AM.

  2. #2
    Join Date
    Dec 2011
    Posts
    10

    Default

    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

  3. #3
    Join Date
    Dec 2011
    Posts
    10

    Default

    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 at 04:50 PM.

  4. #4
    Join Date
    Dec 2011
    Posts
    10

    Default

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

  5. #5
    Join Date
    Nov 2010
    Posts
    175

    Default

    @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.
    Roy Clarkson
    Spring Mobile Projects Lead

  6. #6
    Join Date
    Dec 2011
    Posts
    10

    Default

    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.

  7. #7
    Join Date
    Nov 2010
    Posts
    175

    Default

    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.
    Roy Clarkson
    Spring Mobile Projects Lead

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •