title: Creating a @JsonMixin annotation for spring controllers
body: <p>I am using spring with jackson for json responses.</p>
  
  <p>I want to create an annotation to allow a feature of jackson called mixins.  The idea is similar to this question <a href="https://stackoverflow.com/questions/11853883/using-jackson-mixins-with-mappingjacksonhttpmessageconverter-spring-mvc">Using Jackson Mixins with MappingJacksonHttpMessageConverter &amp; Spring MVC</a></p>
  
  <pre><code>public @interface JsonMixin{
    public class target();
    public class mixin();
  }
  
  @Retention(RetentionPolicy.RUNTIME)
  @Target(ElementType.METHOD)
  public @interface JsonFilter{
      public JsonMixin[] mixins();
  }
  </code></pre>
  
  <p>Usage:</p>
  
  <pre><code>@JsonFilter(mixins={
    @JsonMixin(target=Target1.class, mixin=Mixin1.class),
    @JsonMixin(target=Target2, mixin=Mixin2.class)
  })
  @RequestMapping(value = "/accounts/{id}",
          produces = MediaType.APPLICATION_JSON_VALUE,
          method = RequestMethod.GET)
  @ResponseBody
  @ResponseStatus(value = HttpStatus.OK)
  public final Account getAccountsViaQuery(@PathParam("id") final long id) 
          throws IOException {
      return accountService.get(id);
  }
  </code></pre>
  
  <p>Normally (without the annotations) it would be done as follows:</p>
  
  <pre><code>@RequestMapping(value = "/accounts/{id}",
          produces = MediaType.APPLICATION_JSON_VALUE,
          method = RequestMethod.GET)
  @ResponseBody
  @ResponseStatus(value = HttpStatus.OK)
  public final Account getAccountsViaQuery(@PathParam("id") final long id) 
          throws IOException {
  final String matchingAccounts = accountService.findByAccountNameOrNumber(query);
      ObjectMapper mapper = new ObjectMapper();
      SerializationConfig serializationConfig = mapper.getSerializationConfig();
      serializationConfig.addMixInAnnotations(Target1.class, Mixin1.class);
      serializationConfig.addMixInAnnotations(Target2.class, Mixin2.class);
  
      return mapper.writeValueAsString(matchingAccounts);
  }
  </code></pre>
  
  <p>Using this custom annotation how would I link into the internal object mapper and tell it to use the mixins supplied by the annotations?</p>