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

邮差的信 提交于 2019-12-13 13:29:31

问题


I have a JAXB generated class containing the following:

@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:

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

If I comment out the @Pattern constraint, the JUnitTest runs fine.

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

Regards, PM.


回答1:


@Pattern is for Strings, you cannot apply it to a Short. Instead, you can use @Max and/or @Min. @Digits may be even better.

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



回答2:


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



来源:https://stackoverflow.com/questions/13457276/no-validator-could-be-found-for-type-java-lang-short

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!