Cannot disable resteasy-jaxb-provider in favor of jackson2
lostiniceland Dec 18, 2017 8:15 AMHello everyone
We are migrating a legacy application from Portal to Wildfly 10 and we need to load some custom XML into our application.
The XML classes are annotated with JAXB and a resteasy-client with jackson-xml-provider is used to unmarshall the XMLs.
public class ResteasyJacksonXmlReader {
public ResteasyJacksonXmlReader() {
}
T readEntity(String url, Class clazz) {
JacksonXmlModule jacksonXmlModule = new JacksonXmlModule();
jacksonXmlModule.setDefaultUseWrapper(false);
JacksonJaxbXMLProvider provider = new JacksonJaxbXMLProvider();
XmlMapper mapper = new XmlMapper(jacksonXmlModule);
// Configure JAXB
JaxbAnnotationModule jaxbAnnotationModule = new JaxbAnnotationModule();
mapper.registerModule(jaxbAnnotationModule);
// configure as necessary mapper.configure(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT, true);
mapper.configure(DeserializationFeature.ACCEPT_EMPTY_ARRAY_AS_NULL_OBJECT, true);
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
mapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true);
mapper.configure(DeserializationFeature.FAIL_ON_MISSING_CREATOR_PROPERTIES, false);
provider.setMapper(mapper);
ResteasyClient client = new ResteasyClientBuilder().build();
client.register(provider);
ResteasyWebTarget target = client.target(url);
Response response = target.request().get();
T result = response.readEntity(clazz);
return result;
}
}
This code works as expected as junit-test but when deploying this code, Wildfly always falls back to the com.sun.xml which fails
Caused by: org.jboss.resteasy.plugins.providers.jaxb.JAXBUnmarshalException: com.sun.xml.bind.v2.runtime.IllegalAnnotationsException: 1 counts of IllegalAnnotationExceptions
I've followed the instructions to manually enable jackson using a deployment-structure.xml (implicit activation does not work since there are no jax-rs annotations).
I disabled the resteasy-jaxb-provider because it has the dependency to com.sun.xml and enabled all modules that I need. There are two dependencies which are not provided by Wildfly, those are supplied within the ear
- jackson-jaxrs-xml-provider
- jackson-dataformat-xml
Even though I disabled the resteasy-jaxb-provider, the plugin is still used as you could see in the stacktrace.
What am I missing?
NOTE: We are deploying an EAR with multiple WARs