Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/azure/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring中的自定义JSON序列化_Json_Spring_Spring Boot_Jackson_Spring Restcontroller - Fatal编程技术网

Spring中的自定义JSON序列化

Spring中的自定义JSON序列化,json,spring,spring-boot,jackson,spring-restcontroller,Json,Spring,Spring Boot,Jackson,Spring Restcontroller,我有三个实体: @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

我有三个实体:

@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;
    ... 
}
但我需要的不是日程安排,而是关于团队的信息:

group.name:groupName

}

只需创建一个具有字段id、name和groupName的视图模型类。在RestController中,您必须将课程实体映射到视图模型类,并返回视图模型类型的and对象。@Evgeni创建一个包装器并返回它?是的,它类似于包装器。查看视图模型模式-。JPA实体是您的模型,视图模型是您在网页上显示的。@Evgeni我理解,谢谢。我认为有两种方式序列化对象的更好的解决方案,Json视图,这是一个Jackson mapper特性。请看这里:但我不确定它是否涵盖了您的用例。
{
id: 1,
name: name,