How to validate bean on Spring's WebClient?
Asked Answered
C

2

7

I guess the answer is no, as all references to Bean Validation in the documentation are related to the server side.

Is there any support for Bean Validation on the client's side? So that I can validate my entities before even sending them to the server.

Chincapin answered 31/7, 2019 at 16:37 Comment(0)
V
3

EDIT

You can use Apache Commons Validator which is part of JSR-303 implementations

Apache Commons Validator provides the building blocks for both client side validation and server side data validation. It may be used standalone or with a framework like Struts.

Or use relevant proprietary client-side solution

JSR-303 doesn’t cover client-side validation, so web frameworks supporting this JSR need to come up with proprietary client-side solutions. Tapestry provides client-side validation for the following JSR-303 constraints

Virtuosic answered 23/10, 2019 at 13:21 Comment(2)
Strange, as JPA "client"/ EntityManager is supported. And neither Jackson nor Spring WebClient provide any out-of-the-box integration?Utta
The question (title) was about Spring WebClient. It shouldn't depend on the device type, should it?Utta
C
0

You can call validator manually:

@Autowired
private final SmartValidator validator;

BeanPropertyBindingResult errors = new BeanPropertyBindingResult(entity, "entity");
validator.validate(entity, errors);
if (errors.hasErrors()) {
    //...
}
Conciliator answered 25/10, 2019 at 7:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.