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

@JsonInclude(JsonInclude.Include.NON_NULL does not work for double

我正在尝试在 route!=0 的情况下检索 {"status":201} 但我得到 {"status":201,"distance":0.0} 我怎样才能用 @JsonInclude 或杰克逊也没有 "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 class:

@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) 不能为空(它们有默认值)