虚拟客户响应验证

时间:2020-01-24 14:08:40

标签: java spring validation annotations feign

我有两个应用程序A和B使用FeignClient相互通信。 作为应用程序A,我希望对应用程序B返回的数据进行验证。如果要验证请求参数,我可以轻松地使用@Valid批注并使用正确的spring验证批注对对象进行批注。那回应呢?

@FeignClient()
public interface AccountClient {
   @PostMapping("/accounts/account/create")
   void createAccount(@Valid CreateAccountRequest request);

   @PostMapping("/accounts/account/get")
   AccountResponse getAccount(AccountRequest request);

}
public classs AccountResponse {
   @NotNull
   public String status;
}

以代码为例。我可以轻松地在应用程序B中验证CreateAccountRequest。但是AccountResponse呢?在这种情况下,@ NotNull无法正常工作。我宁愿避免获得响应并手动检查状态是否为!= null,因为我会有更多这样的字段。

1 个答案:

答案 0 :(得分:0)

在这种情况下,如果将DATE,VALUE,QUALITY,STATE,FILENAME,PRODUCT,TAG 2018-06-01,73.83,Good,0,dinosaur.csv,water,Benjamin.Field.12.Location53.Readings 2018-06-02,45.53,Good,0,dinosaur.csv,water,Benjamin.Field.12.Location53.Readings 2018-06-03,89.123,Good,0,dinosaur.csv,water,Benjamin.Field.12.Location53.Readings 放置在@Validated界面上,然后将AccountClient放置在@Valid方法上,则响应验证应该起作用。

getAccount
相关问题