這是與其他服務(wù)兼容的休息請(qǐng)求:{ "fromDate": 1562773101000, "toDate": 1563118701000, "turnOverType": 4, "fromAmount": 1, "toAmount": 10000000, "voucherDescription": null, "articleDescription": null, "referenceNumbers": [], "offset": 3, "pageSize": 20, "iban": "BLAHBLAHBLAHBLAH"}這是與請(qǐng)求不匹配的對(duì)應(yīng)模型:@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 填充。但我想為這種情況獲得一個(gè)例外,并向客戶提出一個(gè)錯(cuò)誤的請(qǐng)求。我怎樣才能做到這一點(diǎn)?如果我在 rest 請(qǐng)求和 model 之間遇到名稱沖突或類型沖突,我需要處理它并向客戶發(fā)出錯(cuò)誤的請(qǐng)求。我正在使用 spring mvc 5 和 jackson-core 以及 jackson-databind 2.9.4
1 回答

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