0
votes

For OTP length I am using 6, which I am taking from a variable

static final int OTP_LENGTH = 6;

@Size(min = OTP_LENGTH, max = OTP_LENGTH, message = "OTP Length should be {OTP_LENGTH} !!")
private String otp;

For which I am getting error mesage, if size is not of OTP_LENGTH.

"fieldErrors": [
    {
      "field": "password",
      "message": "Not a Base64 string !!"
    },
    {
      "field": "otp",
      "message": "OTP Length should be {OTP_LENGTH} !!"
    }
  ]

I also tried

@Size(min = OTP_LENGTH, max = OTP_LENGTH, message = "OTP Length should be ${OTP_LENGTH} !!")
private String otp;

But, OTP_LENGTH 6 is not setting.

Expectation :- "OTP Length should be 6 !!"

And, is there any other validator which takes only 1 length.

@Size, @Length can take max, @Size(max = OTP_LENGTH), but again min will be 0. If I will not override message, it will show length should be between 0 & 6.

1
What is the actual message which you do currently see? - Tim Biegeleisen
"message": "OTP Length should be {OTP_LENGTH} !!". It's not replacing with 6 - Satish Patro
what about: OTP Length should be '${OTP_LENGTH}' ? - Andriy Budzinskyy
tried. No luck. - Satish Patro

1 Answers

2
votes

You have to use min and max fields from @Size annotation, e.g.:

@Size(min = OTP_LENGTH, max = OTP_LENGTH, message = "OTP Length must be between {min} and {max}")
private String otp;

For value, you can validatedValue property.