Ignoring xml namespace during unmarshalling in RestTemplate

I send XML through an HTTP request through Spring RestTemplate to an external gateway and I get an XML response.

The XSD that was given the answer confirmation has a target namespace, but the actual response does not contain a namespace prefix. I created Java resources using XSD, and because of this, I get below errors when receiving a response (during the unmarshalling process),

ResponseEntity<Response> responseEntity = restTemplate.exchange(endpointURL, HttpMethod.POST, requestEntity, Response.class); 

The exception is: -

 Exception in thread "main" javax.xml.bind.UnmarshalException: unexpected element (uri:"", local:"Response"). Expected elements are <{http://securetransport.dw/rcservice/xml}Response> 

Is there a way to skip namespace validation from Spring ResponseEntity?

+6
source share
1 answer

If you created the bindings using jaxb-plugin, there should be "package-info.java".

For instance:

@javax.xml.bind.annotation.XmlSchema( namespace = "someurl", elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED )

If you remove the namespace from the annotation, it should work.

+2
source

All Articles