這是與其他服務兼容的休息請求:{ "fromDate": 1562773101000, "toDate": 1563118701000, "turnOverType": 4, "fromAmount": 1, "toAmount": 10000000, "voucherDescription": null, "articleDescription": null, "referenceNumbers": [], "offset": 3, "pageSize": 20, "iban": "BLAHBLAHBLAHBLAH"}這是與請求不匹配的對應模型:@XmlAccessorType(XmlAccessType.FIELD)public class TransferRequestInquiryFilter implements Serializable { @XmlElement(name = "sourceIbans") private List<String> sourceIbans; @XmlElement(name = "transferType") private TransferType transferType; @XmlElement(name = "fromTransferDate") private Timestamp fromTransferDate; @XmlElement(name = "toTransferDate") private Timestamp toTransferDate; @XmlElement(name = "fromRegistrationDate") private Timestamp fromRegistrationDate; @XmlElement(name = "toRegistrationDate") private Timestamp toRegistrationDate; @XmlElement(name = "trackingNumbers") private List<String> trackingNumbers; @XmlElement(name = "referenceNumbers") private List<String> referenceNumbers; @XmlElement(name = "transactionIds") private List<String> transactionIds; @XmlElement(name = "status") private TransactionStatus status; @XmlElement(name = "fromAmount") private Long fromAmount; @XmlElement(name = "toAmount") private Long toAmount; @XmlElement(name = "destinationIbans") private List<String> destinationIbans;}只是 fromAmount 和 toAmount 填充。但我想為這種情況獲得一個例外,并向客戶提出一個錯誤的請求。我怎樣才能做到這一點?如果我在 rest 請求和 model 之間遇到名稱沖突或類型沖突,我需要處理它并向客戶發出錯誤的請求。我正在使用 spring mvc 5 和 jackson-core 以及 jackson-databind 2.9.4
1 回答

白衣非少年
TA貢獻1155條經驗 獲得超0個贊
@validated
使用 validation-api,為字段和before 控制器方法注釋正確的驗證,并使用@valid
beforeRequestBody
對象將拋出正確的驗證異常。
添加回答
舉報
0/150
提交
取消