我有一个Spring控制器类,它返回带有@ResponseBody的JSON。但奇怪的是,它返回双字段的整数。我使用JacksonMapper作为JSON库。这是课程。
Phone
public class Phone implements Serializable {
@JsonProperty(value="phoneid")
private long phoneId;
private Plan plan;
private String sim;
private String imei;
@JsonProperty(value="phonetype")
private String phoneType;
@JsonProperty(value="phonenumber")
private String phoneNumber;
private String label;
@JsonProperty(value="connecteddate")
private String connectedDate;
//getters and setters
}
Plan
public class Plan implements Serializable {
@JsonProperty(value="planid")
private long planId;
@JsonProperty(value="planname")
private String planName;
private double billingIncrement;
private double owiStdUnitCost;
private double owiFlagFall;
private double stdCap;
private double dataCap;
private double smsCap;
private double owiDataUnitCost;
private double owiSms;
//getters and setters
}
PhoneResult
public class PhoneResult implements Serializable {
private boolean ok;
private String message;
private Phone result;
//getters and setters
}
当我返回PhoneResult对象时,它会返回如下:
{
"ok": true,
"message": "",
"result":
{
"phoneid": 600003,
"phonenumber": "12343423",
"phonetype": "Samsung Galaxy S2",
"imei": "343242",
"sim": "1234324",
"label": "Mr Bean",
"connecteddate": "2012-09-19 00:00:00.0",
"plan":
{
"planid": 34,
"planname": "$59 Jeenee Plan",
"billingIncrement": 30,
"owiStdUnitCost": 81.8181818181818,
"owiFlagFall": 0,
"stdCap": 636.3636,
"dataCap": 227.2665,
"smsCap": 1363.638,
"owiDataUnitCost": 0.022194,
"owiSms": 22.7272727272727
}
}
}
billingIncrement和owiFlagFall具有整数类型,即使这些字段在类和数据库中是双精度类型。我不想关心这个,但是当我使用Spring resttemplate将return JSON转换为object时,我会导致错误。如果这些字段具有30.0和0.0等双重类型,则不会导致任何错误。这看起来很奇怪,但确实如此。 你能给我任何建议吗?您的回答将不胜感激。