我有一个看起来像这样的JSON
{
"uniqueId":"junk",
"buildingId":"123",
"famousFor":[
{
"famousForId":"asd",
"name":"Gaming",
"activeState":true
}
],
"openHours":[
{
"day":"Sunday",
"timingsFrom":{
"time":"11:00",
"meridian":"AM"
},
"timingsTo":{
"time":"11:59",
"meridian":"PM"
}
}
],
"uploadedImages":{
"coverPhoto":[
{
"imageUrl":"http://google.com/images/a123a.png",
"activeState":false
}
],
"profilePhoto":[
{
"imageUrl":"http://google.com/images/a123a.png,
" activeState":false
}
]
},
"fDescriptions":[
{
"fMapUrl":"http://google.com/images/a123a.png",
"tag":"1"
}
],
"Outlets":[
{
"outletName":"Halo",
"floorNumber":1,
"category":"Gaming"
}
]
}
现在,我必须创建一个GET API,该API实际上将为我提供具有空值的相同模板。返回对象时,它向我发送了空值。如何标准化外观相同的模板。我的对象看起来像这样。
public class EssentialDetails {
@NotBlank(message=ApplicationUtil.MISSING_FIELD)
@Valid
@Pattern(regexp = "[0-9]+$",message="DP ID Must be Number")
String dpId;
@Id @NotBlank(message= ApplicationUtil.MISSING_FIELD)
@Valid
@Pattern(regexp = "[A-Za-z0-9]+$",message="Must Be Combination of Number and Letters")
String tpId;
@NotNull(message=ApplicationUtil.MISSING_FIELD) @Valid
List<FamousFor> famousFor;
@NotNull(message=ApplicationUtil.MISSING_FIELD) @Valid
List<OpenHours> openHours;
@NotNull(message=ApplicationUtil.MISSING_FIELD) @Valid
Pictures uploadedImages;
@NotNull(message=ApplicationUtil.MISSING_FIELD) @Valid
List<FloorDescription> floorDescriptions;
@NotNull(message=ApplicationUtil.MISSING_FIELD) @Valid
List<Outlets> mallOutlets;
}
如何在模板中包含每个字段的情况下传递空模板?我正在使用Java 8和Spring Boot 2.0.6。
答案 0 :(得分:0)
如果为空或为null,或者注释下方的某些有效值可以在模型属性的上方使用
@JsonInclude(ALWAYS)