title: Overriding included provider in Jersey
body: <p>I need to make a custom ExceptionMapper in Jersey to handle the JsonProcessingException returned by Jackson. </p>
  
  <p>The Jackson library already includes ExceptionMapper providers for this exception in the form of JsonMappingExceptionMapper.java and JsonParseExceptionMapper.java (<a href="https://github.com/FasterXML/jackson-jaxrs-json-provider/tree/master/src/main/java/com/fasterxml/jackson/jaxrs/json" rel="noreferrer">link</a>).</p>
  
  <p>If I add a new provider for this exception mapper in "my.package" I get unpredictable results regarding the selected provider. Sometimes it will select the provider in "my.package" and sometimes it will select the provider in the Jackson library. The code I'm using to scan the packages is below.</p>
  
  <pre><code>PackgesResourceConfig packagesResourceConfig = new PackgesResourceConfig("com.fasterxml.jackson.jaxrs", "my.package");
  </code></pre>
  
  <p><strong>Proposed Solution</strong></p>
  
  <p>Currently I am getting around this by filtering out the provider in the Jackson library manually. But what I really want to know is whether there is a more acceptable and supported way of doing this.</p>
  
  <p>First I extend PackagesResourceConfig.</p>
  
  <pre><code>public class FilteredPackgesResourceConfig extends PackagesResourceConfig {
  
      private Set&lt;Class&lt;?&gt;&gt; classesToFilter = new HashSet&lt;Class&lt;?&gt;&gt;();
  
      public FilteredPackgesResourceConfig(String... packages) {
          super(packages);
      }
  
      public FilteredPackgesResourceConfig(Map&lt;String, Object&gt; props) {
          super(props);
      }
  
      @Override
      public Set&lt;Class&lt;?&gt;&gt; getClasses() {
          Set&lt;Class&lt;?&gt;&gt; classes = super.getClasses();
  
          if (classes != null &amp;&amp; classesToFilter != null) {
              classes.removeAll(classesToFilter);
          }
  
          return classes;
      }
  
      public Set&lt;Class&lt;?&gt;&gt; getClassesToFilter() {
          return classesToFilter;
      }
  
      public void setClassesToFilter(Set&lt;Class&lt;?&gt;&gt; classesToFilter) {
          this.classesToFilter = classesToFilter;
      }
  }
  </code></pre>
  
  <p>This I use this class to filter out the specific providers I don't want.</p>
  
  <pre><code>FilteredPackgesResourceConfig packagesResourceConfig = new FilteredPackgesResourceConfig("com.fasterxml.jackson.jaxrs", "my.package");
  classesToFilter.add(com.fasterxml.jackson.jaxrs.json.JsonMappingExceptionMapper.class);       
  classesToFilter.add(com.fasterxml.jackson.jaxrs.json.JsonParseExceptionMapper.class);
  packagesResourceConfig.setClassesToFilter(classesToFilter);
  </code></pre>
  
  <p>This solution gives me the desired result of only using the providers I specified.
  Is there a more correct way of achieving the same result?</p>