Reputation: 31
I am trying to validate a simple DTO:
@Data
public class Dto {
@NotNull
private Integer anInt;
@AssertTrue
public boolean isIntCustomValid() {
return anInt == 123 || anInt == 999;
}
}
In my Controller, with @Valid. When anInt
is null, isIntCustomValid
is still validated and I get this error because anInt
is null:
HV000090: Unable to access
If I remove isIntCustomValid
, then @NotNull works correctly.
I want to validate these separately.
I tried using @GroupSequence
and @Groups
, which works, but I have to create empty marker interfaces which is does not seem like an elegant solution.
Upvotes: 3
Views: 602
Reputation: 1
If you got HV000090
, then should be handle exceptions like this:
[Link][1]
@AssertTrue
public boolean isIntCustomValid() {
if( (Objects.nonNull(anInt) ) {
return anInt == 123 || anInt == 999;
}
return true;
}
[enter image description here][1]
[1]: https://i.sstatic.net/u8Jpr.jpg
Upvotes: 0