且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

字符串的Java验证器

更新时间:2023-11-07 19:26:58

这是不可能的. JSON反序列化和Bean验证完全是两个 .到您的Hibernate验证生效时,它会看到一个带有单个名称字段的Person对象.

This is not possible. JSON deserialization and Bean validation are two entirely different things. By the time your Hibernate validation kicks in all it sees is a Person object, with a single name field.

JSON库的行为将确定哪些名称"字段将反序列化到Java bean中(或者是否引发异常).在大多数情况下,如果要验证是否没有重复项,则需要编写一些自定义反序列化代码.

It is the behavior of your JSON library that will determine which of the "name" fields will be deserialized into the Java bean (or if an exception will be thrown). For the most part, if you want to validate that no duplicates are supplied then you are going to need to write some custom deserialization code.