【发布时间】:2015-05-24 08:16:10
【问题描述】:
我正在尝试在route!=0 的情况下检索{"status":201},但我得到{"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;
}
}
【问题讨论】:
-
你能展示你的 Json 对象吗?
-
@JordiCastilla:你对 json 对象有什么看法?杰克逊图书馆创建了所有内容后,我没有?