- 请求第三方系统,调用第三方API时可能会遇到双方协商定义的响应体中某个字段的首字母为大写的情况:
响应体:
{
"PlannerId": test123,
"Name": "testName",
"operation": null,
}
使用大写字母的字段去接收响应体时,其实API请求的每一个返回值都是小写的。所以映射关系找不到导致该值为null。
原因:spring使用HttpMessageConverter将返回实体转换为json
解决方法:
@JsonProperty(value = "PlannerId")
private String plannerId;
- 使用restTepmlate 请求时假若所传的参数中有含有首字母大写的,请求被拒绝,返回无效的参数,参数异常等
原因:使用fastjson的JSONObject.toJSONString(vo)将参数名大写自动转换为小写
解决方法:
@JsonFiled(name = "PlannerId")
private String plannerId;