考虑以下我使用Postman提取或放置一些值的json正文:
{
"server":
{
"address":"ITEM-EX30099",
"port":10500
},
"instance":{
"instance-name":"instance",
"instance-number":100252,
"date":"20190429"
}
}
当我调试代码时,我注意到我放在上述json正文中的所有信息都没有改变,除了日期值(从20190429
到Mon Dec 31 01:00:00 CET 2018
莫名其妙地变化)
有人知道我为什么会有这个问题吗?
这是控制器的方法:
@RequestMapping(value = "/{instanceName}/{action}", method = RequestMethod.PUT, consumes = "application/json")
public ResponseEntity putInstanceStatus(@PathVariable(name = "action") String action, @RequestHeader(HeaderFilter.USER_KEY) String username, @RequestHeader(HeaderFilter.PASSWORD_KEY) String password,
@RequestBody ServerInstanceRequestWrapper serverInstanceRequestWrapper)
{
InstanceActionResponse instanceActionResponse = instanceService.putInstanceStatus(action, username, password, serverInstanceRequestWrapper.getServer(), serverInstanceRequestWrapper.getInstance().getInstanceName(), String.valueOf(serverInstanceRequestWrapper.getInstance().getInstanceNumber()), serverInstanceRequestWrapper.getInstance().getDate().toString());
return ResponseEntity.ok(instanceActionResponse);
}
在实例类中,这是我声明日期属性的方式:
@JsonProperty("date")
@JsonFormat(pattern = "YYYYMMdd")
private Date date;