Java @JsonInclude(JsonInclude.Include.NON_NULL对double不起作用
我正在尝试检索Java @JsonInclude(JsonInclude.Include.NON_NULL对double不起作用,java,json,jersey,jackson,Java,Json,Jersey,Jackson,我正在尝试检索{“status”:201}在路由!=0的情况下,但是我得到了{“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
{“status”:201}
在路由!=0的情况下,但是我得到了{“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;
}
}
@JsonInclude(JsonInclude.Include.NON_NULL)
公共类SDBean{
公众地位;
公共航线;
公共双距离;
公共SDBean(){
状态=230;
}
公共字符串toJson(){
ObjectMapper mapper=新的ObjectMapper();
字符串json=null;
试一试{
json=mapper.writeValueAsString(this);
}捕获(JsonProcessingException e){
e、 printStackTrace();
}
System.out.println(json);
返回json;
}
}
使用Double
。原语(Double
)不能为空(它们有默认值)你能显示你的Json对象吗?@JordiCastilla:你对Json对象有什么看法?我没有jackson libraray创建所有东西的时候?或者可以使用OptionalDouble
来明确意图?(尽管您也需要注册JDK8模块)