1 Reply Latest reply on Dec 18, 2017 8:05 AM by lostiniceland

    Cannot disable resteasy-jaxb-provider in favor of jackson2

    lostiniceland

      Hello 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

        • 1. Re: ResteasyClient with Jackson-XML for JAXB annotated classes (Wildfly always falls back to resteasy-jaxb-provider which uses com.sun.xml)
          lostiniceland

          As it turns out, the exclusion within the deployment was not enough. It was necessary to specify the exclusions for the sub-deployment.

          Even stranger, the jackson2-provider must be specified in the global deployment (otherwise the WAR cannot link the classes).

           

          <?xml version="1.0" encoding="UTF-8"?>
          <jboss-deployment-structure>
            <ear-subdeployments-isolated>true</ear-subdeployments-isolated>
            <deployment>
             <exclusions>
             <module name="org.jboss.resteasy.resteasy-jackson-provider"/>
             <module name="org.jboss.resteasy.resteasy-jettison-provider"/>
             <module name="org.jboss.resteasy.resteasy-jaxb-provider"/>
             </exclusions>
          
             <dependencies>
             <module name="org.dom4j"/>
             <module name="org.jboss.resteasy.resteasy-jackson2-provider" services="import" />
             <module name="com.fasterxml.jackson.jaxrs.jackson-jaxrs-json-provider" />
             </dependencies>
            </deployment>
            <sub-deployment name="sparda-shop-0.0.1-SNAPHOT.war">
             <exclusions>
             <module name="org.jboss.resteasy.resteasy-jackson-provider"/>
             <module name="org.jboss.resteasy.resteasy-jettison-provider"/>
             <module name="org.jboss.resteasy.resteasy-jaxb-provider"/>
             </exclusions>
            </sub-deployment>
          </jboss-deployment-structure>
          

          Unfortunately this is not documented very well. We've just came accross some comment in the forums saying that exclusions work differently for EARs and WARs.