有一个带有以下字段的 Errors 类:
public class Errors {
private String name;
private String email;
private String photo;
private String title;
private String text;
private String image;
private String code;
private String password;
private String captcha;
}
如何使空字段不显示在json中:
{
"result": false,
"errors": {
"name": null,
"email": "Этот e-mail уже зарегистрирован",
"photo": null,
"title": null,
"text": null,
"image": null,
"code": null,
"password": "Пароль короче 6-ти символов",
"captcha": null
}
}
请告诉我
一般来说,没办法,因为它依赖于 JSON 库。
默认情况下,SpringBoot 使用 Jackson。
或
application.properties添加我将补充@AlexanderPetrov 的答案
如果您使用Google Gson
null,则默认情况下不序列化具有值的字段:相反,要序列化,
null您需要尝试: