这是与其他服务兼容的休息请求:{ "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
提交
取消