[英]jackson serialize reference with partial information
Suppose I have 2 types of entity: 假设我有两种类型的实体:
Owner{
String name;
@OneToMany
List<Hotel> hotels;
}
Hotel{
String name;
String address;
int price;
}
I want to serialize these entity as: 我想将这些实体序列化为:
owner:
{
"name":"xxx",
"hotels": [{"name":x, "price":1}]
}
hotel:
{
"name":"x",
"address": "111 yyy",
"price": 1
}
Basically I want to only display a partial information of hotel in owner serialization, but full information in hotel serialization. 基本上,我只希望在所有者序列化中显示旅馆的部分信息,而在旅馆序列化中显示全部信息。 Is there a way to do this beside a customized serializer of Owner? 除了所有者的自定义序列化程序之外,还有其他方法吗?
Thanks. 谢谢。
You can use @JsonIgnoreProperties
annotation from jackson-annotations package. 您可以从jackson-annotations包中使用@JsonIgnoreProperties
注释。
public class Owner {
private String name;
@JsonIgnoreProperties("address")
private List<Hotel> hotels;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.