我正在使用 spring boot REST,我想在序列化期间更改 JSON 响应的结构。我有以下型号:
标题.java
@Entity
public class Title {
private Short id;
private String name;
private Collection<TitleCelebrity> titleCelebrities;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
public Short getId() {
return id;
}
public void setId(Short id) {
this.id = id;
}
@Basic
@Column(name = "name")
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@OneToMany(mappedBy = "title")
public Collection<TitleCelebrity> getTitleCelebrities() {
return titleCelebrities;
}
public void setTitleCelebrities(Collection<TitleCelebrity> titleCelebrities) {
this.titleCelebrities = titleCelebrities;
}
}
TitleCelebrity.java
@Entity
@Table(name = "title_celebrity")
public class TitleCelebrity {
private TitleCelebrityPK id;
private String characterName;
private Title title;
private TitleCelebrityType titleCelebrityType;
@EmbeddedId
@JsonIgnore
public TitleCelebrityPK getId() {
return id;
}
public void setId(TitleCelebrityPK id) {
this.id = id;
}
@Basic
@Column(name = "character_name")
public String getCharacterName() {
return characterName;
}
public void setCharacterName(String characterName) {
this.characterName = characterName;
}
@MapsId("titleByTitleId")
@ManyToOne
@JoinColumn(name = "title_id", referencedColumnName = "id", nullable = false)
@JsonIgnore
public Title getTitle() {
return title;
}
public void setTitle(Title title) {
this.title = title;
}
相关分类