Cannot find validator for type: java.lang.Short

I have a generated JAXB class containing the following:

@Pattern(regexp = "[0-9]", message = "Message details here") protected Short msgVal; 

When I run a JUnit test to test an instance of this class through Hibernate, I get:

javax.validation.UnexpectedTypeException: No validator could be found for type: java.lang.Short .

If I comment on the @Pattern constraint, JUnitTest is working fine.

Is it possible to have @Pattern restrictions on short values? If so, what am I missing?

Regards, PM.

+4
source share
2 answers

@Pattern for strings, you cannot apply it to Short. Instead, you can use @Max and / or @Min. @ Digital can be even better.

 @Digits(integer=1, fraction=0) protected Short msgVal; 
+6
source

no @Pattern annotation just accepts arguments as String. You can use @Digits(message="message here", integer=32767, fraction = 0)

0
source

Source: https://habr.com/ru/post/1447002/


All Articles