原对象属性字段如下:
private String wInsertDt;
生成的get方法如下:
public String getwInsertDt() {
return wInsertDt;
}
springboot 在返回json对象时会默认把字段首字母大写变成小写,是根据get方法来转换,而我的字段(wInsertDt)首字母不是大写,它竟然把第二个字母变成了小写,我也是醉了,返回的结果如下:
{
"periodWid": "20170811",
"synthesizeCode": "MPAY201720831",
"incomePeriod": "201708",
"classCode": "044031900211",
"invoiceId": "00837223",
"invoiceAmount": 2632367.55,
"taxAmount": 3436.4,
"invoiceDate": "20170911",
"drawer": "张三",
"invoiceStatus": "1",
"sign": "3AACCABEF1A7CFD9C8163F77EED63AE5",
**"winsertDt": "2020-01-17 13:48:35"**
}
最后从网上找到的解决方法
@JsonProperty("wInsertDt")
private String wInsertDt;
@JsonIgnore
public String getwInsertDt() {
return wInsertDt;
}
字段属性加上注解@JsonProperty(“wInsertDt”)指定序列化后的名称,字段属性的get方法加上注解@JsonIgnore,如果不加这个注解会出现json里面同时有大小写区分的和大小写不区分的
同理,首字母为大写的属性字段也可以用这种方法解决问题