gpt4 book ai didi

java - @JsonInclude(JsonInclude.Include.NON_NULL 不适用于 double

转载 作者:行者123 更新时间:2023-11-29 05:05:44 37 4
gpt4 key购买 nike

route!=0 的情况下,我正在尝试检索 {"status":201} 但我得到的是 {"status":201 "distance":0.0} 如何使用 @JsonInclude 或 Jackson 也没有 "distance":0.0

SDBean bean = new SDBean();
if (routeD != 0) {
// Insert the data into the bus table
bean.status = db.insertData(macD, routeD, latD, longD);

return Response.status(bean.status).entity(bean.toJson()).build();

}

SDBean 类:

@JsonInclude(JsonInclude.Include.NON_NULL)
public class SDBean {

public int status;
public ArrayList<Integer> routes;
public double distance;

public SDBean(){
status = 230;
}

public String toJson() {

ObjectMapper mapper = new ObjectMapper();
String json = null;
try {
json = mapper.writeValueAsString(this);
} catch (JsonProcessingException e) {
e.printStackTrace();

}
System.out.println(json);
return json;
}
}

最佳答案

使用 double 。原语 (double) 不能为空(它们有默认值)

关于java - @JsonInclude(JsonInclude.Include.NON_NULL 不适用于 double,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30421413/

37 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com