@JsonInclude(JsonInclude.Include.NON_NULL)对double不适用。

问题描述 投票:1回答:1

我想找回 {"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;
    }
}
java json jersey jackson
1个回答
3
投票

使用 Double...基元 (double)不能为空(它们有默认值)

© www.soinside.com 2019 - 2024. All rights reserved.