[英]JAX-RS serialize only few properties
We have a DTO like below我们有一个像下面这样的 DTO
public class Student {
private String name;
private String id;
private ExamResults results;
private Address residentialAddress;
private Address permanentAddress;
// setter and getter methods
}
The same DTO is used by multiple endpoints like student/details/{studId}, student/details/{studId}/results多个端点使用相同的 DTO,例如 student/details/{studId}、student/details/{studId}/results
In student/details/{studId} endpoint we dont populate results
property.在 student/details/{studId} 端点中,我们不填充results
属性。 But still it is being returned as null in the response.但它仍然在响应中被返回为 null。
Similarly, in student/details/{studId}/results we dont populate permanentAddress
and residentialAddress
, but still these are being returned as null in the response.类似地,在 student/details/{studId}/results 中我们没有填充permanentAddress
和residentialAddress
,但这些在响应中仍然作为空返回。
Basically, I would like to control what properties are serialized based on the endpoint irrespective of whether they are null or not.基本上,我想控制基于端点序列化哪些属性,而不管它们是否为空。
Thanks.谢谢。
You can try to use你可以尝试使用
@JsonInclude(JsonInclude.Include.NON_NULL)
public class Student {
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.