Custom JSON serialization in Spring

2019-09-05 07:58发布

I have three entities:

@Entity
class Group {
    @id
    Long id;
    String name;
    String faculty;
@OneToMany(mappedBy = "group", fetch = FetchType.LAZY, cascade = CascadeType.ALL )
    List<Schedule> scedule;
    ...
}

@Entity
class Schedule {
    @id
    Long id;
    String name;
    Group group;
    @OneToMany(mappedBy = "scedule", fetch = FetchType.LAZY, cascade = CascadeType.ALL )
    List<Lesson> scedule;
    ...
}

@Entity
class Lesson {
    @id
    Long id;
    String name;
    Schedule scedule;
    ... 
}

I use Spring boot, and one my restcontroller return list of Lesson. But i need something like the following JSON for Lesson:

{
id: 1,
name: name,

But instead of schedule i need information about group:

group.name: groupName }

0条回答
登录 后发表回答