Android RestTemplate: How to assign the JSON Message converter
Thats my approach so far:
Code:
//relevant imports:
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.json.MappingJacksonHttpMessageConverter; //shipped w/ RestTemplate
The part w/ the error:
Code:
List<HttpMessageConverter<?>> mc = restTemplate.getMessageConverters();
mc.add(new MappingJacksonHttpMessageConverter()); //throws VerifyError
restTemplate.setMessageConverters(mc);
Thats the Error I am getting:
Code:
java.lang.VerifyError: org.springframework.http.converter.json.MappingJacksonHttpMessageConverter
Re: Android RestTemplate: How to assign the JSON Message converter
The problem is that MappingJacksonHttpMessageConverter internally references org.codehaus.jackson.map.ObjectMapper in a private variable.
Code:
private org.codehaus.jackson.map.ObjectMapper objectMapper;
The codehaus jackson library is not deployed part of the Spring Android RestTemplate code. If you put the *.jar file in your assets library (I used jackson-all-1.6.3.jar), it should work.
Why, do you ask did you get a VerifyError versus a ClassDefNotFound exception which would have pointed it out. I think because it is a private variable fully scoped rather than some like: private ObjectMapper objectMapper; where in this case there would have been an import statement.
Perry Hoekstra