我想找回 {"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;
}
}
使用 Double
...基元 (double
)不能为空(它们有默认值)