title: deserialize lazy loading in hibernate and jackson
body: <p>Is there a way to keep LAZY loading and deserialize the object using the id instead of the POJO object.</p>
  
  <p>I have 2 class that are joined by a many-to-many relationship.</p>
  
  <p>Something like this</p>
  
  <pre><code>public class User {
      @Id
      @JsonProperty
      public long id;
  
      @ManyToMany(
              fetch = FetchType.EAGER,
      )
      @JoinTable(
              name = "User_EntityType",
              joinColumns = @JoinColumn(name = "user_id"),
              inverseJoinColumns = @JoinColumn(name = "type_id")
      )
      @JsonProperty
      public Set&lt;Type&gt; types;
  
  }
  
  public class Type {
      @Id
      @JsonProperty
      public long id;
  
      @ManyToMany(
              fetch = FetchType.EAGER,
              mappedBy = "types",
              targetEntity = User.class
      )
      @JsonProperty
      public Set&lt;User&gt; users;
  }
  </code></pre>
  
  <p>The data type works just fine. I can write and read using hibernate with no issue.</p>
  
  <p>However, I want to be able to return an User object with a REST API, so I'm using Jackson to deserialize it. The issue is when I do that, it deserialize every Type in the User object, which includes other Type objects, and it creates a huge mess.</p>
  
  <p><strong>Is it possible to instead just return the Set of Long type ids instead of Set of Type?</strong></p>