Shadowman
Shadowman

Reputation: 12049

RESTEasy -- "Unexpected element" when unmarshaling JSON?

I am writing a RESTEasy client for Apple's AppStore lookup service, which returns a JSON object representing the results of a query. For my test case the JSON looks like this:

{

 "resultCount":1,

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

   ...<more stuff>...

}]

}

I've created a very simple JAXB object just to see if I can successfully unmarshal a response from the service using my RESTEasy client. I'm only trying to map the "resultCount" property from the response. It looks like this:

@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;
    }

}

However, when I run my client I see the following Exception:

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)

What exactly is causing this to throw an exception? I haven't seen an error like this in the past, and haven't had any success in locating a solution for this problem. Any help you can give is greatly appreciated!!

Upvotes: 1

Views: 2272

Answers (1)

Shadowman
Shadowman

Reputation: 12049

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.

Upvotes: 3

Related Questions