如何从类级别注释违规中获取属性路径
我正在使用 Hibernate 验证器。我有一个类级别的注释。它比较三个属性是否相等。执行验证时,我需要从返回的 javax.validation.ConstraintViolation 对象中获取 PropertyPaths。由于它不是单个字段,因此 getPropertyPath() 方法返回 null。还有其他方法可以找到 PropertyPaths吗?
这是我的注释实现 -
@MatchField.List({
@MatchField(firstField = "firstAnswer", secondField = "secondAnswer", thirdField = "thirdAnswer"),
})
I'm using Hibernate Validator. I have a Class level annotation. It compares three properties for equality. When the validation is performed I need to get the PropertyPaths from the javax.validation.ConstraintViolation object returned. Since it's not a single field the getPropertyPath() method returns null. Is there another way to find the PropertyPaths?
This is my annotation implementation -
@MatchField.List({
@MatchField(firstField = "firstAnswer", secondField = "secondAnswer", thirdField = "thirdAnswer"),
})
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要将消息设置为映射到进行验证时要拒绝的属性。 Hibernate Validator 无法自动找出自定义注释属性是属性路径。
You need to set the messages to map to the properties that you want rejected when you do the validation. Hibernate Validator has no way to auto-magically figure out that custom annotation properties are property paths.