3
votes

My codes hangs when creating a new MappingJacksonHttpMessageConverter. I am running on Android 4.1.2. The code is below

public void login(String empCode, String password) {
    RestTemplate rt = new RestTemplate();
    MappingJacksonHttpMessageConverter jackson = new MappingJacksonHttpMessageConverter();
    try{
        rt.getMessageConverters().add(jackson);
        rt.getMessageConverters().add(new StringHttpMessageConverter());
    } catch(Exception ex) {
        ex.printStackTrace();
    }


    String uri = new String("http://43.68.85.137:8080/cimweb/api/authenticateEmployee");
    Employee employee = new Employee();
    employee.setEmpCode(empCode);
    employee.setPassword(password);
    employee.setAuthenticUser(false);

    Employee returns = rt.postForObject(uri, employee, Employee.class);}

and here is the log

08-14 16:11:41.250: E/dalvikvm(15517): Could not find class 'org.codehaus.jackson.map.ObjectMapper', referenced from method org.springframework.http.converter.json.MappingJacksonHttpMessageConverter. 08-14 16:11:41.250: W/dalvikvm(15517): VFY: unable to resolve new-instance 807 (Lorg/codehaus/jackson/map/ObjectMapper;) in Lorg/springframework/http/converter/json/MappingJacksonHttpMessageConverter; 08-14 16:11:41.250: D/dalvikvm(15517): VFY: replacing opcode 0x22 at 0x000e

5

5 Answers

0
votes

The ObjectMapper is not in your classpath. If you are using Eclipse, right-click in you project and then click on Build path > Configure Build Path...

After that add the necessary jar file. Make sure that you have this both:

http://www.springsource.org/spring-android

http://jackson.codehaus.org/

Get the latest version of both and add them in your classpath.

0
votes

It would seem that the jar containing "ObjectMapper" is not available on the classpath

0
votes

Make sure that you have included both Spring core and rest-template libraries to the project.

0
votes

I ticked the jackson core and mapper and spring-android libraries in the "Order and Export" and it worked

0
votes

You must add jackson jar files into your project see this. The ObjectMapper is in the databind collection.