1

我正在为 Apple 的 AppStore 查找服务编写一个 RESTEasy 客户端,它返回一个表示查询结果的 JSON 对象。对于我的测试用例,JSON 如下所示:

{

 "resultCount":1,

 "results": [
{
    "kind":"software",
     "features":["gameCenter",
     "iosUniversal"],
     "supportedDevices":["all"],
     "isGameCenterEnabled":true,

   ...<more stuff>...

}]

}

我创建了一个非常简单的 JAXB 对象,只是为了查看是否可以使用我的 RESTEasy 客户端成功解组来自服务的响应。我只是想从响应中映射“resultCount”属性。它看起来像这样:

@Mapped
@XmlRootElement
@XmlAccessorType(XmlAccessType.NONE)
public class AppStoreLookupResponse implements Serializable {

    private static final long serialVersionUID = 7589102375949422744L;

    @XmlElement
    private int resultCount = -1;

    /**
     * Returns the resultCount
     * 
     * @return The resultCount
     */
    public int getResultCount() {
        return resultCount;
    }

    /**
     * Sets the resultCount
     * 
     * @param resultCount
     *            The resultCount to set
     */
    public void setResultCount(int resultCount) {
        this.resultCount = resultCount;
    }

}

但是,当我运行我的客户端时,我看到以下异常:

org.jboss.resteasy.plugins.providers.jaxb.JAXBUnmarshalException: javax.xml.bind.UnmarshalException
 - with linked exception:
[com.sun.istack.internal.SAXParseException2; columnNumber: 0; unexpected element (uri:"", local:"resultCount"). Expected elements are <{}appStoreLookupResponse>]
    at org.jboss.resteasy.plugins.providers.jaxb.AbstractJAXBProvider.readFrom(AbstractJAXBProvider.java:86)
    at org.jboss.resteasy.core.interception.MessageBodyReaderContextImpl.proceed(MessageBodyReaderContextImpl.java:105)
    at org.jboss.resteasy.plugins.interceptors.encoding.GZIPDecodingInterceptor.read(GZIPDecodingInterceptor.java:37)
    at org.jboss.resteasy.core.interception.MessageBodyReaderContextImpl.proceed(MessageBodyReaderContextImpl.java:108)
    at org.jboss.resteasy.core.messagebody.ReaderUtility.doRead(ReaderUtility.java:111)
    at org.jboss.resteasy.client.core.BaseClientResponse.readFrom(BaseClientResponse.java:291)
    at org.jboss.resteasy.client.core.BaseClientResponse.getEntity(BaseClientResponse.java:255)
    at org.jboss.resteasy.client.core.BaseClientResponse.getEntity(BaseClientResponse.java:228)
    at org.jboss.resteasy.client.core.extractors.BodyEntityExtractor.extractEntity(BodyEntityExtractor.java:56)
    at org.jboss.resteasy.client.core.ClientInvoker.invoke(ClientInvoker.java:102)
    at org.jboss.resteasy.client.core.ClientProxy.invoke(ClientProxy.java:72)
    at $Proxy20.lookupByID(Unknown Source)
    at net.odyssi.mms.appstore.apple.test.AppleAppStoreLookupClientTest.testLookupByID(AppleAppStoreLookupClientTest.java:111)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:601)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

究竟是什么导致这引发异常?我过去没有看到过这样的错误,也没有成功找到解决这个问题的方法。非常感谢您提供的任何帮助!

4

1 回答 1

3

Finally found an answer to this! I upgraded the RestEASY libraries to 2.3.5, and also removed the Jettison provider JARs in favor of Jackson. That solved all of my issues.

于 2013-05-27T02:16:23.127 回答