Ignore namespace during unmarshalling XML document

2,761 views
Skip to first unread message

DK

unread,
Mar 26, 2014, 3:51:54 PM3/26/14
to rest-a...@googlegroups.com
Is there anyway we can ignore namespace while unmarshalling XML using JAXB.

i get response in either of formats based on environments, can we ignore namespace from the second response below or add namespace dynamically to the first response to work constantly

XML Response:

<foo><bar></bar></foo>

Same response with namespace:

<foo xmlns="http://tempuri.org/"><bar></bar></foo>



Appreciate any help.


Johan Haleby

unread,
Mar 27, 2014, 2:24:22 AM3/27/14
to rest-a...@googlegroups.com
I suppose you need to configure JAXB to ignore namespaces somehow. You can configure Rest Assured's use of JAXB in the configuration:

RestAssured.config = RestAssuredConfig.config().objectMapperConfig(objectMapperConfig().jaxbObjectMapperFactory(
                new JAXBObjectMapperFactory() {
                    public JAXBContext create(Class cls, String charset) {
                        return ..;
                    }
                }
        ));

Regards,
/Johan



--
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/d/optout.

DK

unread,
Mar 27, 2014, 11:14:25 AM3/27/14
to rest-a...@googlegroups.com
Thanks Johan for the reply, I looked at those options before but I'm blank from there i don't know how we do configuration to ignore namespace, i googled earlier and i found something on stackoverflow but not sure how we can integrate that solution into rest-assured. here is the link http://stackoverflow.com/questions/277502/jaxb-how-to-ignore-namespace-during-unmarshalling-xml-document. please advise me the elaborated solution. 

thanks

Johan Haleby

unread,
Mar 28, 2014, 10:41:51 AM3/28/14
to rest-a...@googlegroups.com
It seems like it's not enough to configure the JAXBContext that is provided by the object mapper factory in REST Assured in this case. I think you'll have to roll your own object mapper in REST Assured. Doing so will give you full control over the serialization and de-serialzation process.

/Johan


DK

unread,
Mar 31, 2014, 12:10:47 PM3/31/14
to rest-a...@googlegroups.com
Thanks Johan, its done.
Reply all
Reply to author
Forward
0 new messages