title: JAX-RS Custom @Provider for a subset of the type
body: <p>I have an API with the following return type:</p>
  
  <pre><code>class Example {
    private Complex1 complex1;
    private Complex2 complex2;
  }
  </code></pre>
  
  <p>Complex1 and Complex2:</p>
  
  <pre><code>class Complex1 {
    private String test1;
    private String test2;
  }
  
  class Complex2 {
    private String test3;
    private String test4;
  }
  </code></pre>
  
  <p>Now I would like to make use of standard serialization for Complex1 but add custom serialization for Complex2.</p>
  
  <p>I tried to add a Provider for Complex2. But JAX-RS seems to be not aware of it since it is not the actual return type. If I add a Provider for Example JAX-RS makes use of my custom Provider. But having a custom Provider for Example has the drawback that I have to add logic for Complex1 too although standard serialization would be OK for Complex1.</p>
  
  <p>In this example it would be OK, to do serialization for Complex1 too, but in my scenario Complex1 is huge and would like to avoid implementing serialization logic for Complex1.</p>
  
  <p>Do you have any advice?</p>