Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java @JsonInclude(JsonInclude.Include.NON_NULL对double不起作用_Java_Json_Jersey_Jackson - Fatal编程技术网

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模块)