Bean validation size of a List?

I created simple class: public class Mock { @Size(min=1, max=3) private List<String> strings; public List<String> getStrings() { return strings; } public void set(List<String> strings) { this.strings = strings; } } And test: Mock mock = new Mock(); mock.setStrings(Collections.emptyList()); final Set<ConstraintViolation<Mock>> violations1 = Validation.buildDefaultValidatorFactory().getValidator().validate(mock); assertFalse(violations1.isEmpty()); mock.setStrings(Arrays.asList(“A”, “B”, “C”, “D”)); final Set<ConstraintViolation<Mock>> violations2 = Validation.buildDefaultValidatorFactory().getValidator().validate(mock); assertFalse(violations2.isEmpty()); It … Read more

kotlin data class + bean validation jsr 303

You need to use Annotation use-site targets since the default for a property declared in the constructor is to target the annotation on the constructor parameter instead of the getter (which will be seen by JavaBeans compliant hosts) when there are multiple options available. Also using a data class might be inappropriate here (see note … Read more

Annotations from javax.validation.constraints not working

For JSR-303 bean validation to work in Spring, you need several things: MVC namespace configuration for annotations: <mvc:annotation-driven /> The JSR-303 spec JAR: validation-api-1.0.0.GA.jar (looks like you already have that) An implementation of the spec, such as Hibernate Validation, which appears to be the most commonly used example: hibernate-validator-4.1.0.Final.jar In the bean to be validated, … Read more

How can I validate two or more fields in combination?

For multiple properties validation, you should use class-level constraints. From Bean Validation Sneak Peek part II: custom constraints: Class-level constraints Some of you have expressed concerns about the ability to apply a constraint spanning multiple properties, or to express constraint which depend on several properties. The classical example is address validation. Addresses have intricate rules: … Read more

In Hibernate Validator 4.1+, what is the difference between @NotNull, @NotEmpty, and @NotBlank?

@NotNull: The CharSequence, Collection, Map or Array object is not null, but can be empty. @NotEmpty: The CharSequence, Collection, Map or Array object is not null and size > 0. @NotBlank: The string is not null and the trimmed length is greater than zero. To help you understand, let’s look into how these constraints are … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)