Hi,
We have a Rest service which returns a JSON or XML response if all goes
well and a JSON / XML "Errors" object if a problem occurs. The "Errors"
object has been created using xjc ie. by generating a JAXB class from a
Schema.
Our JAXB provider looks like this:
JAXBElementProvider jaxbElementProvider = new JAXBElementProvider
();
In our JSON provider we have specified no namespaces should be used in the
response:-
JSONProvider jsonProvider = new
org.apache.cxf.jaxrs.provider.json.JSONProvider();
jsonProvider.setDropRootElement(false);
jsonProvider.setSupportUnwrapped(true);
jsonProvider.setIgnoreNamespaces(true);
jsonProvider.setSchemaHandler(schemaHandler);
jsonProvider.setValidateOutput(true);
In our integration tests we have code as follows:-
assertEquals(400, response.getStatus());
Errors errors = response.readEntity(Errors.class);
assertEquals("ABC_001", errors.getError().get(0).getCode());
ie. we are asserting we get the correct HTTP status code back and that we
get an Errors object containing an Error with a specific sub error code.
This works fine when using XML as the mime type but when using JSON, our
code fails at the line: Errors errors = response.readEntity(Errors.class)
with the following exception:
javax.ws.rs.MessageProcessingException: javax.ws.rs.BadRequestException:
com.sun.istack.SAXParseException2; columnNumber: 0; unexpected element
(uri:"", local:"ns2.Errors"). Expected elements are <
{http://www.xx.com/schema/framework/ErrorV01}Errors>
at org.apache.cxf.jaxrs.impl.ResponseImpl.doReadEntity
(ResponseImpl.java:335)
at org.apache.cxf.jaxrs.impl.ResponseImpl.readEntity
(ResponseImpl.java:286)
at org.apache.cxf.jaxrs.impl.ResponseImpl.readEntity
(ResponseImpl.java:276)
Is there anyway to get the response.readEntity() method to ignore
namespaces?
Many thanks
Mandy