1

我正在尝试将 json 发送到服务器,但出现以下异常:

从处理程序 [public void com.hexgen.api.facade.HexgenWebAPI.createInvestAdjust(com.hexgen.ro.request.InvestAdjustRO,boolean)] 解决异常:org.springframework.http.converter.HttpMessageNotReadableException:无法读取 JSON:格式无效:“01/09/2012”在“/09/2012”处格式错误(通过参考链:com.hexgen.ro.request.InvestAdjustRO["transDate"]);嵌套异常是 org.codehaus.jackson.map.JsonMappingException: Invalid format: "01/09/2012" is malformed at "/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: Invalid format: "01/09/2012" is malformed at "/09/2012" (通过参考链: com.hexgen.ro.request.InvestAdjustRO["transDate" ])

谢谢

4

1 回答 1

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;
于 2013-08-13T11:37:56.897 回答