忽略java中构造函数中不存在的Json属性

忽略java中构造函数中不存在的Json属性,java,json,Java,Json,我的课程如下所示:- @Getter @Setter @NoArgsConstructor public class Response extends ResponseMessage { @JsonProperty("ResponseDto") private myDTo myDto; @JsonProperty("revId") private Long revisionId; @JsonProperty("modelId") privat

我的课程如下所示:-

@Getter
@Setter
@NoArgsConstructor
public class Response extends ResponseMessage {

    @JsonProperty("ResponseDto")
    private myDTo myDto;

    @JsonProperty("revId")
    private Long revisionId;

    @JsonProperty("modelId")
    private Long model;

    public Response(HttpStatus status, String message) {
        super(status, message);
    }

    public Response(HttpStatus status, String message, Long revisionId) {
        super(status, message);
        this.revisionId = revisionId;
    }

    public Response(HttpStatus status, String message, Long revisionId, Long modelId) {
        super(status, message);
        this.revisionId = revisionId;
        this.model = modelId;
    }

    public Response(HttpStatus status, String message, myDTo myDto) {
        super(status, message);
        this.myDto = myDto;
    }
}
现在,当我返回Response类作为Response时,如下所示:-

return new Response(HttpStatus.OK,"done",123);
它返回json响应,如下所示:-

{
"revId":123,
"status":"OK",
"modelId":null,
"message":"done"
}
但是用户希望响应依赖于被调用的构造函数。在这种情况下,应该是:-

{
"revId":123,
"status":"OK",
"message":"done"
}

任何帮助都将不胜感激

你应该使用
@JsonInclude(Include.NON\u NULL)
来忽略空字段。

我想这就是你想要的?您可以使用@JsonInclude(Include.NON_NULL)