我正在尝试将json发送到服务器,我得到以下异常:
解决处理程序中的异常[public void com.hexgen.api.facade.HexgenWebAPI.createInvestAdjust(com.hexgen.ro.request.InvestAdjustRO,布尔值)]: org.springframework.http.converter.HttpMessageNotReadableException: 无法读取JSON:格式无效:“01/09/2012”格式错误 “/ 09/2012”(通过参考链: com.hexgen.ro.request.InvestAdjustRO [ “transDate”]);嵌套异常 是org.codehaus.jackson.map.JsonMappingException:格式无效: “01/09/2012”在“/ 09/2012”(通过参考链: com.hexgen.ro.request.InvestAdjustRO [ “transDate”])
这就是我的JSON:
adjustmentType: "UAMORT"
custodian: "DEUTSCHE"
debitCredit: "CREDIT"
investCategory: "FVTPL"
isUploaded: false
portfolio: "HEXGENFUND"
portfolioCcy: "INR"
recRemarks: "Test"
transDate: "01/09/2012"
transRef: "OP120010020000017"
这是我的getter和setter的java代码:
private String transId;
private String portfolio;
private String portfolioCcy;
private String transRef;
private String adjustmentType;
private LocalDate transDate;
private String debitCredit;
private String investCategory;
private String custodian;
private String recRemarks;
private RecStatus recStatus;
private Boolean isUploaded=true;
这里的问题是什么,为什么我会得到
嵌套异常是org.codehaus.jackson.map.JsonMappingException: 格式无效:“01/09/2012”格式错误在“/ 09/2012”(通过 参考链:com.hexgen.ro.request.InvestAdjustRO [“transDate”])
感谢
答案 0 :(得分:1)
尝试使用此注释指定日期格式:
private String transId;
private String portfolio;
private String portfolioCcy;
private String transRef;
private String adjustmentType;
@DateTimeFormat(pattern = "dd/MM/yyyy")
private LocalDate transDate;
private String debitCredit;
private String investCategory;
private String custodian;
private String recRemarks;
private RecStatus recStatus;
private Boolean isUploaded=true;