Re: [rest-assured] MissingMethodException while using JAXB deserialization from JSON response to Object

389 views
Skip to first unread message

Johan Haleby

unread,
Oct 26, 2013, 4:39:49 AM10/26/13
to rest-a...@googlegroups.com
Hi, 

Sorry for the late response, I have broken my hand so have a really hard time answering e-mails :(

Not really sure what's causing the error that you see but it seems to me that it may be a classpath issue. Are you using maven or have you downloaded the zip distribution?

Regards,
/Johan




On Thu, Oct 17, 2013 at 11:33 PM, Deepak M <dme...@gmail.com> wrote:
Hi,

I'm getting the following exception when I try to deserialize a JSON response into an Object using JAXB deserializer. How do I get around this error? Thanks!

Here's my test:
OrderCancellationResponse[] roomCancellationResponses =
                given().log().all()
                .expect().log().all().statusCode(Response.Status.OK.getStatusCode())
                .when().delete(cancelOrder).as(OrderCancellationResponse[].class,
                        ObjectMapperType.JAXB);

Here's how the class looks like:

@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement(name = "cancellation_response")
public final class OrderCancellationResponse {

    @XmlElement(name = "order_status", required = true)
    private StatusType orderStatus;

    @XmlElement(name = "order_id", required = true)
    private String orderId;

}

JSON response is:
[
    {
        "cancelled_at": "2013-10-17T13:57:00-07:00",
    },
    {
        "cancelled_at": "2013-10-17T13:57:00-07:00",
    }
]

Error seen:
groovy.lang.MissingMethodException: No signature of method: com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal() is applicable for argument types: (java.io.StringReader, java.lang.Class) values: [java.io.StringReader@2731f1bc, class [Lcom.abc.order.domain.response.OrderCancellationResponse;]
Possible solutions: unmarshal(javax.xml.stream.XMLEventReader, java.lang.Class), unmarshal(javax.xml.stream.XMLStreamReader, java.lang.Class), unmarshal(javax.xml.transform.Source, java.lang.Class), unmarshal(org.w3c.dom.Node, java.lang.Class), unmarshal(javax.xml.stream.XMLEventReader, java.lang.Class), unmarshal(javax.xml.stream.XMLStreamReader, java.lang.Class)
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:55)
at org.codehaus.groovy.runtime.callsite.PojoMetaClassSite.call(PojoMetaClassSite.java:46)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:120)
at com.jayway.restassured.internal.path.xml.mapping.XmlPathJaxbObjectDeserializer.deserialize(XmlPathJaxbObjectDeserializer.groovy:45)
at com.jayway.restassured.path.xml.mapping.XmlPathObjectDeserializer$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:108)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
at com.jayway.restassured.internal.mapping.JaxbMapper.deserialize(JaxbMapper.groovy:40)
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:108)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
at com.jayway.restassured.internal.mapping.ObjectMapping.parseWithJaxb(ObjectMapping.groovy:176)
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:606)
at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90)
at org.codehaus.groovy.runtime.callsite.StaticMetaMethodSite$StaticMetaMethodSiteNoUnwrapNoCoerce.invoke(StaticMetaMethodSite.java:148)
at org.codehaus.groovy.runtime.callsite.StaticMetaMethodSite.callStatic(StaticMetaMethodSite.java:99)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallStatic(CallSiteArray.java:53)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callStatic(AbstractCallSite.java:157)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callStatic(AbstractCallSite.java:169)
at com.jayway.restassured.internal.mapping.ObjectMapping.deserializeWithObjectMapper(ObjectMapping.groovy:89)
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:606)
at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90)
at org.codehaus.groovy.runtime.callsite.StaticMetaMethodSite$StaticMetaMethodSiteNoUnwrapNoCoerce.invoke(StaticMetaMethodSite.java:148)
at org.codehaus.groovy.runtime.callsite.StaticMetaMethodSite.callStatic(StaticMetaMethodSite.java:99)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallStatic(CallSiteArray.java:53)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callStatic(AbstractCallSite.java:157)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callStatic(AbstractCallSite.java:173)
at com.jayway.restassured.internal.mapping.ObjectMapping.deserialize(ObjectMapping.groovy:47)
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:108)
at com.jayway.restassured.internal.RestAssuredResponseImpl.as(RestAssuredResponseImpl.groovy:181)
at com.abc.order.request.cancel.OrderCancellationTest.testOrderCancel(OrderCancellationTest.java:71)

--
You received this message because you are subscribed to the Google Groups "REST assured" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rest-assured...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Johan Haleby

unread,
Oct 26, 2013, 4:42:15 AM10/26/13
to rest-a...@googlegroups.com
Looking at it more closely at the error you seem to be using JAXB to parse JSON. This doesn't work! JAXB is for XML only, you probably want to use Jackson or Faster Jackson. And if you do you need to have those libraries in the classpath as well.

/Johan 
Reply all
Reply to author
Forward
0 new messages