This is a followup from the question here. How do I add @Valid to a local variable?
Here is code from the class AuthorizationServer:
@NotBlank
private String authorizationServerId;
@Property
@Indexed(unique = true)
@NotBlank
private String authorizationUrl;
@Property(policy = PojomaticPolicy.TO_STRING)
@NotBlank
private String clientAuthorizationUrl;
@NotBlank
private String deviceRootCert;
This is the controller:
byte[] bytes = IOUtils.toByteArray(request.getInputStream());
String signature = authorization.split(":")[1];
ObjectMapper mapper = objectMapper();
AuthorizationServer authorizationServer = mapper.readValue(bytes,
AuthorizationServer.class);
How do I validate the authorizationServer against the annotations declared in the AuthorizationServer class?
When I tried
@Valid
AuthorizationServer authorizationServer = mapper.readValue(bytes, AuthorizationServer.class);
I got the error @Valid not applicable to local variable.
I think the exception says it all. Bean Validation does not allow the validation local variables. It is all about validating class state via property validation or you can do method validation. There is no such thing as local variable validation.