[英]No validator could be found for type: java.lang.Short
I have a JAXB generated class containing the following: 我有一个包含以下内容的JAXB生成的类:
@Pattern(regexp = "[0-9]", message = "Message details here")
protected Short msgVal;
When I run a JUnit test to validate an instance of that class via Hibernate, I get: 当我运行JUnit测试以通过Hibernate验证该类的实例时,我得到:
javax.validation.UnexpectedTypeException: No validator could be found for type: java.lang.Short
. javax.validation.UnexpectedTypeException: No validator could be found for type: java.lang.Short
。
If I comment out the @Pattern
constraint, the JUnitTest runs fine. 如果我注释掉@Pattern
约束,则JUnitTest可以正常运行。
Is it possible to have @Pattern
constraints on Short values? 是否可以对Short值使用@Pattern
约束? If so, what am I missing? 如果是这样,我想念什么?
Regards, PM. 问候,下午。
@Pattern is for Strings, you cannot apply it to a Short. @Pattern用于字符串,不能将其应用于Short。 Instead, you can use @Max and/or @Min. 相反,您可以使用@Max和/或@Min。 @Digits may be even better. @Digits可能更好。
@Digits(integer=1, fraction=0)
protected Short msgVal;
no @Pattern
annotation just takes arguments as String. 没有@Pattern
批注仅将参数作为String。 You can use @Digits(message="message here", integer=32767, fraction = 0)
您可以使用@Digits(message="message here", integer=32767, fraction = 0)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.