将body强制转换为特定类型时的NoSuchMethodError

时间:2015-08-17 14:37:12

标签: java jackson rest-assured

我有一个端点,它返回作为请求结果的数字。但是当我调用一个应该将body解析为特定类型的方法时,它会抛出异常。 RestAssured Jackson包含的传递依赖关系位于1.9.2 version

  Long cardId = response.getBody().as(Long.class);
  • Maven:org.codehaus.jackson:jackson-core-asl:1.9.2
  • Maven:org.codehaus.jackson:jackson-jaxrs:1.9.2
  • Maven:org.codehaus.jackson:jackson-mapper-asl:1.9.2
  • Maven:org.codehaus.jackson:jackson-xc:1.9.2

     java.lang.NoSuchMethodError: com.fasterxml.jackson.databind.ObjectMapper.findAndRegisterModules()Lcom/fasterxml/jackson/databind/ObjectMapper;
        at com.jayway.restassured.mapper.factory.DefaultJackson2ObjectMapperFactory.create(DefaultJackson2ObjectMapperFactory.java:27)
        at com.jayway.restassured.mapper.factory.DefaultJackson2ObjectMapperFactory.create(DefaultJackson2ObjectMapperFactory.java:25)
        at com.jayway.restassured.mapper.factory.ObjectMapperFactory$create.call(Unknown Source)
        at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:110)
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:130)
        at com.jayway.restassured.internal.path.json.mapping.JsonPathJackson2ObjectDeserializer.createJackson2ObjectMapper(JsonPathJackson2ObjectDeserializer.groovy:34)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite$PogoCachedMethodSiteNoUnwrapNoCoerce.invoke(PogoMetaMethodSite.java:207)
        at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite.callCurrent(PogoMetaMethodSite.java:56)
        at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:49)
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:151)
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:171)
        at com.jayway.restassured.internal.path.json.mapping.JsonPathJackson2ObjectDeserializer.deserialize(JsonPathJackson2ObjectDeserializer.groovy:41)
        at com.jayway.restassured.path.json.mapping.JsonPathObjectDeserializer$deserialize.call(Unknown Source)
        at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:110)
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:122)
        at com.jayway.restassured.internal.mapping.Jackson2Mapper.deserialize(Jackson2Mapper.groovy:60)
        at com.jayway.restassured.mapper.ObjectMapper$deserialize.call(Unknown Source)
        at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:110)
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:122)
        at com.jayway.restassured.internal.mapping.ObjectMapping.parseWithJackson2(ObjectMapping.groovy:188)
        at com.jayway.restassured.internal.mapping.ObjectMapping$parseWithJackson2$0.callStatic(Unknown Source)
        at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallStatic(CallSiteArray.java:53)
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callStatic(AbstractCallSite.java:191)
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callStatic(AbstractCallSite.java:211)
        at com.jayway.restassured.internal.mapping.ObjectMapping.deserialize(ObjectMapping.groovy:51)
        at com.jayway.restassured.internal.mapping.ObjectMapping$deserialize.call(Unknown Source)
        at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:110)
        at com.jayway.restassured.internal.RestAssuredResponseOptionsGroovyImpl.as(RestAssuredResponseOptionsGroovyImpl.groovy:206)
        at com.jayway.restassured.internal.RestAssuredResponseOptionsImpl.as(RestAssuredResponseOptionsImpl.java:153)
    

    我已经尝试加入jackson annotationdatabindcore,但它没有帮助。

0 个答案:

没有答案