unable to marshal type "java.util.HashMap" as an element because it is missing an @XmlRootElement annotation]

1,398 views
Skip to first unread message

Anurag Gupta

unread,
Apr 24, 2017, 7:12:42 AM4/24/17
to REST assured
Getting this error while passing Map objects to post rest 


 Map<String, Object> payloadparam = new HashMap<>();
 payloadparam.put("user", "Asmsa1");
 payloadparam.put("password", "Asmsa1");


 Response response1= given().accept(ContentType.JSON).and().given().config(config.sslConfig(new SSLConfig().relaxedHTTPSValidation())).body(payloadparam).when().post(url);



getting following error kindly help 


[com.sun.istack.internal.SAXException2: unable to marshal type "java.util.HashMap" as an element because it is missing an @XmlRootElement annotation]
at com.sun.xml.internal.bind.v2.runtime.MarshallerImpl.write(Unknown Source)
at com.sun.xml.internal.bind.v2.runtime.MarshallerImpl.marshal(Unknown Source)
at javax.xml.bind.helpers.AbstractMarshallerImpl.marshal(Unknown Source)
at javax.xml.bind.Marshaller$marshal$0.call(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:133)
at io.restassured.internal.mapping.JaxbMapper.serialize(JaxbMapper.groovy:52)
at io.restassured.mapper.ObjectMapper$serialize.call(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125)
at io.restassured.internal.mapping.ObjectMapping.serializeWithJaxb(ObjectMapping.groovy:186)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:93)
at org.codehaus.groovy.runtime.callsite.StaticMetaMethodSite$StaticMetaMethodSiteNoUnwrapNoCoerce.invoke(StaticMetaMethodSite.java:151)
at org.codehaus.groovy.runtime.callsite.StaticMetaMethodSite.callStatic(StaticMetaMethodSite.java:102)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallStatic(CallSiteArray.java:56)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callStatic(AbstractCallSite.java:194)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callStatic(AbstractCallSite.java:214)
at io.restassured.internal.mapping.ObjectMapping.serialize(ObjectMapping.groovy:123)
at io.restassured.internal.mapping.ObjectMapping$serialize.call(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
at io.restassured.internal.RequestSpecificationImpl.body(RequestSpecificationImpl.groovy:829)
at testbasics.Test_Form_Params.TestPostMethods(Test_Form_Params.java:57)
at testbasics.Test_Form_Params.main(Test_Form_Params.java:74)
Caused by: com.sun.istack.internal.SAXException2: unable to marshal type "java.util.HashMap" as an element because it is missing an @XmlRootElement annotation
at com.sun.xml.internal.bind.v2.runtime.XMLSerializer.reportError(Unknown Source)
at com.sun.xml.internal.bind.v2.runtime.ClassBeanInfoImpl.serializeRoot(Unknown Source)
at com.sun.

 


Johan Haleby

unread,
Apr 24, 2017, 7:23:19 AM4/24/17
to rest-a...@googlegroups.com
You need to specify the content type to be ContentType.JSON

--
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+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Anurag Gupta

unread,
Apr 25, 2017, 2:40:06 AM4/25/17
to REST assured
Hi Johan ,

 I have already specified content type as JSON .

 Response response1= given().accept(ContentType.JSON).and().given().config(config.sslConfig(new SSLConfig().relaxedHTTPSValidation())).


If anywhere else I need to specify kindly brief



To unsubscribe from this group and stop receiving emails from it, send an email to rest-assured...@googlegroups.com.

Johan Haleby

unread,
Apr 25, 2017, 2:49:43 AM4/25/17
to rest-a...@googlegroups.com
No you haven't, you've specified the accept header to indicate to the server that you accept JSON responses. You need to do given.contentType(ContentType.JSON) .. 

To unsubscribe from this group and stop receiving emails from it, send an email to rest-assured+unsubscribe@googlegroups.com.

Selenium Webdriver Automation

unread,
Apr 25, 2017, 4:26:47 AM4/25/17
to REST assured
Thanks , My Bad it worked by doing so . Thanks for your help 

Saurabh Garg

unread,
Jul 21, 2017, 4:10:04 AM7/21/17
to REST assured
I am also getting the same error, don't know why


given().
body(CommonPayLoad.payLoadData("register-device")).
when().
post(CommonResource.resgisterDevice()).
then().assertThat().statusCode(200).and().contentType(ContentType.JSON).extract().response()
Reply all
Reply to author
Forward
0 new messages