-
Bug
-
Resolution: Done
-
Major
-
3.1.4.Final
-
None
If a ContextResolver for JAXBContext is used, RestEasy uses the custom JAXBContext only for creating a Marshaller object. The Unmarshaller is never used.
I have attached two war files. One with the reference implementation jersey and one with resteasy 3.1.4.Final. Boath are runnable on Tomcat 8.5.23. (Sources are also attached)
Implemented is a demo service, with a post method. The service accepts a UserType object and returns the same object.
If the jersey implementation is used, the marshaller and the unmarshaller from the custom context are used.
If resteasy is used, only the marshaller is used. The createUnmarshaller Method is never called.
Because of that, it is impossible to configure the JAX-BContext (e.g. for schema validation)
Sources of the custom JAXB Provider (Full sources can be found in src.zip)
@Provider @Produces(MediaType.APPLICATION_XML) @Consumes(MediaType.APPLICATION_XML) public class JaxbProvider implements ContextResolver<JAXBContext> { @Override public JAXBContext getContext(Class<?> type) { return new CustomJAXBContext(type); } }
Source of CustomJAXBContext
public class CustomJAXBContext extends JAXBContext { private JAXBContext delegate; public CustomJAXBContext(Class<?> type) { try { this.delegate = JAXBContext.newInstance(type.getPackage().getName()); } catch (JAXBException e) { throw new IllegalStateException("Error creating JAXBContext", e); } } @Override public Unmarshaller createUnmarshaller() throws JAXBException { System.out.println("Creating unmarshaller"); return this.delegate.createUnmarshaller(); } @Override public Marshaller createMarshaller() throws JAXBException { System.out.println("Creating marshaller"); return this.delegate.createMarshaller(); } @Override public Validator createValidator() throws JAXBException { return this.delegate.createValidator(); } }