Announcement Announcement Module
Collapse
No announcement yet.
Exception in Spring Android with Spring Rest Template Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Exception in Spring Android with Spring Rest Template

    I am trying to access a rest webservice with Json,

    below is the code in Activity class which i am using to retireve the values

    List<HttpMessageConverter<?>> messageConverters = new ArrayList<HttpMessageConverter<?>>();
    messageConverters.add(new FormHttpMessageConverter());
    messageConverters.add(new StringHttpMessageConverter());
    messageConverters.add(new MappingJacksonHttpMessageConverter());
    restTemplate.setMessageConverters(messageConverter s);
    restTemplate.setRequestFactory(new HttpComponentsClientHttpRequestFactory());
    UserCredentials result1 = restTemplate.getForObject(url,UserCredentials.clas s,userName, password);

    I am getting the following error :

    java.lang.NoSuchMethodError: org.codehaus.jackson.map.ObjectMapper.getTypeFacto ry

    at org.springframework.http.converter.json.MappingJac ksonHttpMessageConverter.getJavaType(MappingJackso nHttpMessageConverter.java:116)
    at org.springframework.http.converter.json.MappingJac ksonHttpMessageConverter.canRead(MappingJacksonHtt pMessageConverter.java:93)
    at org.springframework.web.client.RestTemplate$Accept HeaderRequestCallback.doWithRequest(RestTemplate.j ava:529)
    at org.springframework.web.client.RestTemplate.doExec ute(RestTemplate.java:460)
    at org.springframework.web.client.RestTemplate.execut e(RestTemplate.java:425)
    at org.springframework.web.client.RestTemplate.getFor Object(RestTemplate.java:223)


    But when i hit the URL in browser, i am getting the response as {"userName":"admin","userRole":"admin","valid":"fa lse"}

    can u anyone help me on this

  • #2
    Mmmmm.... Everything looks good.

    What does your dependency entry look like in your pom.xml?

    Comment


    • #3
      I didnt used maven, but i got all these jars in my build path
      commons-httpclient-3.1
      jackson-core-asl-1.6.1
      jackson-mapper-asl-1.6.1
      jersey-client-1.9-ea04
      spring-android-rest-template-1.0.0.M4.jar
      spring-beans-3.0.5.RELEASE.jar
      spring-core-3.0.5.RELEASE.jar

      thanks

      Comment


      • #4
        dutchman , i have tried with maven and i got the same error, here i am posting my pom.xml


        <dependencies>
        <dependency>
        <groupId>com.google.android</groupId>
        <artifactId>android</artifactId>
        <version>
        2.3.3
        </version>
        <scope>provided</scope>
        </dependency>
        <dependency>
        <groupId>org.springframework.android</groupId>
        <artifactId>spring-android-rest-template</artifactId>
        <version>1.0.0.M4</version>
        </dependency>
        <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-core</artifactId>
        <version>3.0.5.RELEASE</version>
        </dependency>
        <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-beans</artifactId>
        <version>3.0.5.RELEASE</version>
        </dependency>
        <dependency>
        <groupId>org.codehaus.jackson</groupId>
        <artifactId>jackson-mapper-asl</artifactId>
        <version>1.6.1</version>
        </dependency>
        <dependency>
        <groupId>org.codehaus.jackson</groupId>
        <artifactId>jackson-core-asl</artifactId>
        <version>1.6.1</version>
        </dependency>
        </dependencies>


        thanks

        Comment


        • #5
          My assumption in that you have some overlap. The following is a pom.xml I have been using successfully on a project.

          <dependencies>
          <dependency>
          <groupId>com.google.android</groupId>
          <artifactId>android</artifactId>
          <version>2.1.2</version>
          <scope>provided</scope>
          </dependency>
          <dependency>
          <groupId>org.springframework.android</groupId>
          <artifactId>spring-android-rest-template</artifactId>
          <version>1.0.0.M3</version>
          </dependency>
          <dependency>
          <!-- Using Jackson for JSON marshaling -->
          <groupId>org.codehaus.jackson</groupId>
          <artifactId>jackson-mapper-asl</artifactId>
          <version>1.7.2</version>
          </dependency>
          </dependencies>

          You do not need the spring-core/spring-beans, just the rest-template. I would upgrade to Jackson 1.7.2.

          Comment


          • #6
            thanks for ur reply. Now my application is working fine. But i am facing problems gen\R.java in maven. Its getting generated in target\generated-sources\ folder. any idea ?

            Comment


            • #7
              Maven and the plugins use alternate directories from the standard Android SDK. If you are having issues with R.java refreshing, I will sometimes run "mvn clean" from the command line, and delete the gen folder. It seems that sometimes it gets a little stuck. The gen folder will be automatically recreated.

              Comment


              • #8
                Spring version m4 needs Jackson version > 1.8

                I would recommend using Jackson 1.8.5
                And spring m4 rest template and core

                Comment

                Working...
                X