将另一个对象传递给当前的休息服务不会抛出异常

这是与其他服务兼容的休息请求:


{

  "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



神不在的星期二
浏览 123回答 1
1回答

白衣非少年

@validated使用 validation-api,为字段和before 控制器方法注释正确的验证,并使用@validbeforeRequestBody对象将抛出正确的验证异常。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java