title: single custom serializer for all embedded annotated objects that replaces them with their ids
body: <p>I have entities like those: </p>
  
  <pre><code>@Entity
  public Product {
     @Id
     public int id;
  
     public String name;
  
     @ManyToOne(cascade = {CascadeType.DETACH} )
     Category category
  
     @ManyToMany(cascade = {CascadeType.DETACH} )
     Set&lt;Category&gt; secondaryCategories;
  
  
  }
  </code></pre>
  
  <p>and</p>
  
  <pre><code>@Entity
  public Category {
     @Id
     public int id;
  
     public String name;
  
      @JsonCreator
      public Category(int id) {
          this.id = id;
      }
  
      public Category() {}
  }
  </code></pre>
  
  <p>is it possible to annotate either just <code>Category</code> class or <code>category</code> and <code>secondaryCategories</code> properties with an annotation that will serialize them to be just their ids when they are embedded.</p>
  
  <p>right now I am getting from the server when I make a GET for product with id=1:</p>
  
  <pre><code>{ 
    id: 1,
    name: "product 1", 
    category: {id: 2, name: "category 2" }, 
    secondaryCategories: [{id: 3, name: "category 3" }, 
                          {id: 4, name: "category 4" }, 
                          {id: 5, name: "category 5" }] 
  }
  </code></pre>
  
  <p>is it possible to get back:</p>
  
  <pre><code>{ 
    id: 1,
    name: "product 1", 
    category: 2, 
    secondaryCategories: [3, 4, 5]
  }
  </code></pre>
  
  <p>Annotating <code>Category</code> class with <code>@JsonIdentityReference(alwaysAsId = true)</code>
  works generally but also returns just ids when I am fetching one or a list of Categories. I need id conversion only when Category is embedded.</p>
  
  <p>Thanks!</p>