jackson JsonInclude Non_Null不忽略对嵌套对象属性的处理

jackson JsonInclude Non_Null不忽略对嵌套对象属性的处理,json,spring,jackson,Json,Spring,Jackson,公共类TrackInformation扩展了AbstractRecord{ @JsonInclude(JsonInclude.Include.NON_NULL) public class Flight implements Serializable { private TrackInformation trackInformation; private MiscData miscData; private CargoItems cargoItems; } C

公共类TrackInformation扩展了AbstractRecord{

@JsonInclude(JsonInclude.Include.NON_NULL)
public class Flight implements Serializable {

    private TrackInformation trackInformation;

    private MiscData miscData;

    private CargoItems cargoItems;

}



Controller class

  

 @RequestMapping(value = "/getFlightByKey", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
public Flight getFlightByKey(@RequestBody @Valid final FlightInfoRequestDTO request)throws NoDataFoundException  {
    return flightInfoAppService.getFlightByKey(request.getKey());
}
}

公共抽象类AbstractRecord实现了可序列化{

}

现在,返回的flight对象具有嵌套对象的空字段。如何忽略嵌套对象中的空字段


hashCode和equals是否在TrackInformation中重写。

您应该在每个嵌套类上添加
@JsonInclude(JsonInclude.Include.NON_NULL)
,以忽略嵌套类的NULL值属性

private static final long serialVersionUID = -5226745652646434627L;

private String sourceFacility;

private ComputerID computerID;

private String sourceTimeStamp;

private Double latitude;

private Double longitude;

private ReportedAltitude reportedAltitude;

private Integer speed;

您还应该在每个嵌套类上添加
@JsonInclude(JsonInclude.Include.NON\u NULL)
,以忽略嵌套类的NULL值属性

private static final long serialVersionUID = -5226745652646434627L;

private String sourceFacility;

private ComputerID computerID;

private String sourceTimeStamp;

private Double latitude;

private Double longitude;

private ReportedAltitude reportedAltitude;

private Integer speed;

是否可以显示嵌套类
TrackInformation
?是否可以显示嵌套类
TrackInformation