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

我正在使用 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;

    }


子衿沉夜
浏览 103回答 1
1回答
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java