java.lang.VerifyError:MappingJacksonHttpMessageConverter,我需要什么样的jackson版本?

时间:2012-04-09 09:11:10

标签: android json spring rest jackson

我使用Android Spring Framework和Jackson解析器开发Android 3.1应用程序。我没有使用Maven,因为我不知道如何使用它。

我已按以下顺序将以下jar添加到我项目的类路径中:

  • 番石榴11.0.2.jar
  • 杰克逊 - 注解-2.0.0.jar
  • 杰克逊 - 芯 - 2.0.0.jar
  • 杰克逊 - 数据绑定-2.0.0.jar
  • 弹簧机器人核-1.0.0.RC1.jar
  • 弹簧机器人静止模板-1.0.0.RC1.jar

发出REST请求并执行JSON解析的类:

import java.util.Arrays;
import java.util.Collections;
import java.util.List;

import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.json.MappingJacksonHttpMessageConverter;
import org.springframework.web.client.RestTemplate;

import com.google.common.collect.Lists;

import es.viacognita.models.Form;

public class FormSpringController
{
    public static List<Form> LoadAll()
    {
        HttpHeaders requestHeaders = new HttpHeaders();
        requestHeaders.setAccept(Collections.singletonList(new MediaType("application","json")));
        HttpEntity<?> requestEntity = new HttpEntity<Object>(requestHeaders);

        String url = "http://192.168.1.128/RestServiceImpl.svc/forms/";

        MappingJacksonHttpMessageConverter messageConverter = new MappingJacksonHttpMessageConverter();
        List<HttpMessageConverter<?>> messageConverters = Lists.newArrayList();
        messageConverters.add(messageConverter);

        RestTemplate restTemplate = new RestTemplate();
        restTemplate.setMessageConverters(messageConverters);

        ResponseEntity<Form[]> responseEntity = restTemplate.exchange(url, HttpMethod.GET, requestEntity, Form[].class);
        Form[] result= responseEntity.getBody();

        return Arrays.asList(result);
    }
}

下面:

MappingJacksonHttpMessageConverter messageConverter = new MappingJacksonHttpMessageConverter();

我收到此错误:

java.lang.VerifyError: org.springframework.http.converter.json.MappingJacksonHttpMessageConverter


为什么我会收到此错误?
我怎么解决呢?

1 个答案:

答案 0 :(得分:2)

问题是Spring不适用于Jackson 2.0。这已通过以下方式解决:

<bean id="jacksonMessageConverter"
          class="own.implementation.of.MappingJacksonHttpMessageConverter"/>

<bean class="org.springframework.web.servlet.mvc
             .annotation.AnnotationMethodHandlerAdapter">
        <property name="messageConverters">
            <list>
                <ref bean="jacksonMessageConverter"/>
            </list>
        </property>
        <property name="requireSession" value="false"/>
    </bean>

own.implementation.of.MappingJacksonHttpMessageConverter基于此:

http://www.jarvana.com/jarvana/view/org/springframework/spring-web/3.0.0.RELEASE/spring-web-3.0.0.RELEASE-sources.jar!/org/springframework/http/converter/json/MappingJacksonHttpMessageConverter.java?format=ok

但是使用ObjectMapper和Jackson 2.0中的其他Jackson类而不是Jackson 1。*