Validation in Middleware Services called from Rest API

Hi,
I’m trying to use validation in service methods called from Rest API,
for example I have the method:

public String ope1 (@NotNull Srv1Ope1ReqDTO req, @NotNull String str)

inside the Srv1Ope1ReqDTO class I have the property with @NotNull:
@Valid
@NotNull
private BIN bin;

If I call the method from Postman the validation works only for the second parameter (“str”) but not for the first (req).

if I use programmatic validation in the method body:

Validator validator = beanValidation.getValidator();
Set<ConstraintViolation> violations = validator.validate(cb);

it works (violations is not empty if req.bin is null).

Can you help me yo understand my mistake?
Thankyou very much
Massimo

Hi,
You probably forgot the @Valid annotation before the req parameter. The @Valid is required to perform the cascaded validation of the parameter:

public String ope1 (@NotNull @Valid Srv1Ope1ReqDTO req, @NotNull String str)

Hi Max,
yes, now it works.

Thank you
Massimo