Answer the question
In order to leave comments, you need to log in
How to deserialize Entity when using @JsonIdentityReference(alwaysAsId=true)?
There are related objects Master - Detail
public class Master {
private long id;
@OneToMany(mappedBy = "detail")
@JsonIgnore
private Collection<Detail> detail;
}
public class Detail {
private long id;
@ManyToOne
@JoinColumn(name = "master_id", referencedColumnName = "id", nullable = false)
@JsonIdentityInfo(generator=ObjectIdGenerators.PropertyGenerator.class, property="id")
@JsonIdentityReference(alwaysAsId=true)
private Master master;
}
@JsonIdentityReference(alwaysAsId=true)
. As a result, in the response I get an ID instead of the Master object. Answer the question
In order to leave comments, you need to log in
Separate Entity entities and POJO entities into different classes and serialize/deserialize via Mapper classes. Although this will increase the number of classes, it will simplify the further support of the application - internal and external entities can "scatter" in content over time.
If this option is not suitable, then write your own deserializer , in which you get the desired entity by ID.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question