title: When overriding JacksonJsonProvider.writeTo, can I specify the view used to serialize?
body: <p>I have a setup with Resteasy-3.0.6, Jackson-2.2.3 and CDI (running on Wildfly-8.0.0.CR1). In my case, every entity has a mix-in class that extends it and specifies the attributes that are to be serialized. There are two "views", let's call them <em>Basic</em> and <em>Extended</em>. Since what kind of view of an object I need depends on the "root" object of the serialization, these views need to be per object. So I re-use the mix-in classes for that. Example:</p>
  
  <pre><code>public class Job { 
      @Id private Long id;
      @OneToMany(mappedBy="job") private Set&lt;Bonus&gt; bonuses;
  }
  
  public class Bonus {
      @Id private Long id;
      @ManyToOne(optional=false) private Job job;
      private BigDecimal value;
  }
  
  public abstract class JsonJob extends Job { 
      abstract Long getId();
  
      @JsonView({ JsonJob.class })
      abstract Set&lt;Bonus&gt; getBonuses();
  }
  
  public abstract class JsonBonus extends Bonus {
      abstract BigDecimal getValue();
  }
  </code></pre>
  
  <p>Now I'm looking for a way to hook into jackson's serialization process to specify <code>JsonJob</code> as a view iff the root entity is <code>Job</code>. I'm currently using <code>JacksonJsonProvider#writeTo</code>:</p>
  
  <pre><code>@Override
  public void writeTo(Object value, Class&lt;?&gt; type, Type genericType, 
                      Annotation[] annotations, MediaType mediaType, 
                      MultivaluedMap&lt;String, Object&gt; httpHeaders, 
                      OutputStream entityStream) throws IOException {
      Class view = getViewForType(type); // if no mix-in class is set, return Object
      ObjectMapper mapper = locateMapper(type, mediaType);
  
      // require all properties to be explicitly specified for serialization
      mapper.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.NONE);
      mapper.registerModule(new SerializationMixinConf()); // registers all mix-ins
  
      super.writeTo(value, type, genericType, annotations, mediaType, 
          httpHeaders, entityStream);
  }
  </code></pre>
  
  <p>The point is: this works, <em>iff</em> the calling method is annotated <code>@JsonView</code>. <strong>But</strong> since the main user of this is a generic super-class, I can't add the annotation to the method directly. Can someone suggest a way to either set the view in the existing mapper (<code>setSerializationConfig()</code> seems to be gone in jackson-2) or dynamically add the <code>@JsonView</code> to the <code>annotations</code> array?</p>