为了账号安全,请及时绑定邮箱和手机立即绑定

如何在 Spring-boot REST 上使用 Jackson 更改响应结构

如何在 Spring-boot REST 上使用 Jackson 更改响应结构

子衿沉夜 2021-07-01 09:00:40
我正在使用 spring boot REST,我想在序列化期间更改 JSON 响应的结构。我有以下型号:标题.java@Entitypublic 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;    }
查看完整描述

1 回答

  • 1 回答
  • 0 关注
  • 102 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信