Validate elements of a String array with Java Bean Validation

前端 未结 3 1931
Happy的楠姐
Happy的楠姐 2020-12-21 00:44

I have a simple class that has one of its properties as a String array. As per this document, using @Valid on an array, collection etc. will recursively validate each elemen

3条回答
  •  悲哀的现实
    2020-12-21 01:35

    Another thing worth mentioning is the introduction of type annotation in Java 8 which lets you annotate parameterized type

    private List<@MyPattern String> defaultAppAdminRoles;
    

    It's not yet in the bean-validation standard (surely in next version) but already available in hibernate-validator 5.2.1. Blog entry here for further information.

提交回复
热议问题