我试图在{"status":201}
的情况下审核route!=0
,但我得到{"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类:
@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;
}
}
答案 0 :(得分:2)
使用Double
。基元(double
)不能为空(它们具有默认值)