Re: [rest-assured] MissingMethodException while unmarshalling JAXB

426 views
Skip to first unread message

Johan Haleby

unread,
Apr 16, 2013, 7:13:35 AM4/16/13
to rest-a...@googlegroups.com
It doesn't look like Rest Assured supports unmarshalling to an array out of the box? The way I see it you have two options:
  1. Change to:
     List<ResourceElement> resources = expect()
                    .statusCode(OK.getStatusCode())
                    .when()
                    .get("/resources?envClass=u&alias=newAlias")
                    .xmlPath().getList(<root element name>, ResourceElement.class);
  2. Provide your own XmlPathObjectDeserializer to XmlPath (see here for an example) and implement support for unmarshalling to an array using JAXB. If you manage to do so please share to the code and I'll add it to REST Assured.
Could you provide also provider an example of the XML you receive in the response so that I can see if you're really are parsing it correctly?

Regards,
/Johan

On Tue, Apr 16, 2013 at 12:54 PM, Thor Åge Eldby <thoraa...@gmail.com> wrote:
Hi. I got this problem when I try to unmarshall XML-body to JAXB-object.
 
        ResourceElement[] resources = expect()
                .statusCode(OK.getStatusCode())
                .when()
                .get("/resources?envClass=u&alias=newAlias")
                .as(ResourceElement[].class);
The XmlPathJaxbObjectDeserializer seem to try to call the unmarshaller with a StringReader object. Appearently the UnmarshallerImpl do not contain an unmarshal-method which take Reader or StringReader as input. Do I have the wrong unmarshaller?
 
Using RestAssured version 1.8.0, JAXB version 2.2.2 and JDK 1.7 (it also contain JAXB, but it seems to use the non-internal (has also tested with the internal with same result ))
 
Thanks
ThorÅge
 
--
 
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@4515f5b0, class [Lno.nav.aura.envconfig.client.rest.ResourceElement;]
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:601)
 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.deserialize(ObjectMapping.groovy:60)
 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:175)
 at no.nav.aura.envconfig.rest.ResourcesRestUrlTest.putResourceOK(ResourcesRestUrlTest.java:101)
 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:47)
 at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
 at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
 at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
 at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
 at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
 at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
 at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
 at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
 at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
 at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
 at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
 at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
 at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
 at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
 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)
 

--
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.
 
 

Thor Åge Eldby

unread,
Apr 16, 2013, 8:07:03 AM4/16/13
to rest-a...@googlegroups.com
Thank you! That worked great. I'm fine with List instead of array (actually finer :-). Included my code and example for completeness:
 
        List<ResourceElement> list = expect()
                .statusCode(OK.getStatusCode())
                .when()
                .get("/resources?envClass=u&alias=" + alias)
                .xmlPath().getList("collection.resource", ResourceElement.class);
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<collection>
<resource><type>Credential</type><alias>newAlias</alias>...</resource>
</collection>
 
ThorÅge

Johan Haleby

unread,
Apr 16, 2013, 8:33:37 AM4/16/13
to rest-a...@googlegroups.com
Great :)

How ever the first example was wrong since there's no way you could deserialize a root "collection" into a ResourceElement array. Given that you have a class called com.x.y.Collection then you should have done:


com.x.y.Collection collection = expect()

                .statusCode(OK.getStatusCode())
                .when()
                .get("/resources?envClass=u&alias=newAlias")
                .as(Collection.class);
Reply all
Reply to author
Forward
0 new messages