Is there a way to keep LAZY loading and deserialize the object using the id instead of the POJO object.
I have 2 class that are joined by a many-to-many relationship.
Something like this
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<Type> types;
}
public class Type {
@Id
@JsonProperty
public long id;
@ManyToMany(
fetch = FetchType.EAGER,
mappedBy = "types",
targetEntity = User.class
)
@JsonProperty
public Set<User> users;
}
The data type works just fine. I can write and read using hibernate with no issue.
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.
Is it possible to instead just return the Set of Long type ids instead of Set of Type?