有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java@JsonInclude(Include.NON_NULL)不会从内部POJO中删除NULL字段

我的回答结构如下。我正在使用jackson-databind版本2.5.1

public class MyResponse {
    private String entity;

    private Detail detail;

    // public Getter and setter
}

@JsonInclude(Include.NON_NULL)
public class Detail {
    private String name;

    private String location; // location field is null for testing

    // public Getter and setter
}

问题:响应包括location字段,即使它是null

注意:@JsonInclude适用于外部对象,即MyResponse,但不适用于内部POJO类

多谢各位


共 (0) 个答案