JAVA-18601 Update "Java Bean Validation Basics" article (#13654)

* JAVA-18601 Update "Java Bean Validation Basics" article
---------

Co-authored-by: timis1 <noreplay@yahoo.com>
This commit is contained in:
timis1 2023-04-11 12:04:58 +03:00 committed by GitHub
parent 7f009957fe
commit 11169082cf
36 changed files with 100 additions and 123 deletions

View File

@ -13,26 +13,6 @@
</parent>
<dependencies>
<dependency>
<groupId>org.hibernate.validator</groupId>
<artifactId>hibernate-validator</artifactId>
<version>${hibernate-validator.version}</version>
</dependency>
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>javax.el</artifactId>
<version>${javax.el.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${org.springframework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>${org.springframework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
@ -57,11 +37,8 @@
<!--</plugin> </plugins> </build> -->
<properties>
<hibernate-validator.version>6.2.3.Final</hibernate-validator.version>
<hibernate-validator.ap.version>6.2.0.Final</hibernate-validator.ap.version>
<javax.el.version>3.0.0</javax.el.version>
<org.springframework.version>5.3.21</org.springframework.version>
<spring.boot.version>2.7.1</spring.boot.version>
<spring.boot.version>3.0.4</spring.boot.version>
</properties>
</project>

View File

@ -4,14 +4,14 @@ import java.time.LocalDate;
import java.util.List;
import java.util.Optional;
import javax.validation.constraints.AssertTrue;
import javax.validation.constraints.Email;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Past;
import javax.validation.constraints.Size;
import jakarta.validation.constraints.AssertTrue;
import jakarta.validation.constraints.Email;
import jakarta.validation.constraints.Max;
import jakarta.validation.constraints.Min;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Past;
import jakarta.validation.constraints.Size;
public class User {

View File

@ -2,8 +2,8 @@ package com.baeldung.javaxval.bigdecimal;
import java.math.BigDecimal;
import javax.validation.constraints.DecimalMin;
import javax.validation.constraints.Digits;
import jakarta.validation.constraints.DecimalMin;
import jakarta.validation.constraints.Digits;
public class Invoice {

View File

@ -2,12 +2,12 @@ package com.baeldung.javaxval.constraint.composition;
import org.hibernate.validator.constraints.Length;
import javax.validation.Constraint;
import javax.validation.Payload;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import javax.validation.constraintvalidation.SupportedValidationTarget;
import javax.validation.constraintvalidation.ValidationTarget;
import jakarta.validation.Constraint;
import jakarta.validation.Payload;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Pattern;
import jakarta.validation.constraintvalidation.SupportedValidationTarget;
import jakarta.validation.constraintvalidation.ValidationTarget;
import java.lang.annotation.Documented;
import java.lang.annotation.Retention;

View File

@ -11,10 +11,10 @@ import java.lang.annotation.Documented;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
import javax.validation.Constraint;
import javax.validation.Payload;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import jakarta.validation.Constraint;
import jakarta.validation.Payload;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Pattern;
import org.hibernate.validator.constraints.Length;

View File

@ -11,11 +11,11 @@ import java.lang.annotation.Documented;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
import javax.validation.Constraint;
import javax.validation.Payload;
import javax.validation.ReportAsSingleViolation;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import jakarta.validation.Constraint;
import jakarta.validation.Payload;
import jakarta.validation.ReportAsSingleViolation;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Pattern;
import org.hibernate.validator.constraints.Length;

View File

@ -4,9 +4,9 @@ import org.hibernate.validator.constraints.CompositionType;
import org.hibernate.validator.constraints.ConstraintComposition;
import org.hibernate.validator.constraints.Length;
import javax.validation.Constraint;
import javax.validation.Payload;
import javax.validation.constraints.Pattern;
import jakarta.validation.Constraint;
import jakarta.validation.Payload;
import jakarta.validation.constraints.Pattern;
import java.lang.annotation.Documented;
import java.lang.annotation.Retention;

View File

@ -4,9 +4,9 @@ import java.util.List;
import java.util.Optional;
import java.util.OptionalInt;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.PositiveOrZero;
import jakarta.validation.constraints.Min;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.PositiveOrZero;
public class Customer {

View File

@ -2,8 +2,8 @@ package com.baeldung.javaxval.container.validation;
import java.util.Map;
import javax.validation.constraints.Email;
import javax.validation.constraints.NotNull;
import jakarta.validation.constraints.Email;
import jakarta.validation.constraints.NotNull;
public class CustomerMap {

View File

@ -1,8 +1,8 @@
package com.baeldung.javaxval.container.validation.valueextractors;
import javax.validation.valueextraction.ExtractedValue;
import javax.validation.valueextraction.UnwrapByDefault;
import javax.validation.valueextraction.ValueExtractor;
import jakarta.validation.valueextraction.ExtractedValue;
import jakarta.validation.valueextraction.UnwrapByDefault;
import jakarta.validation.valueextraction.ValueExtractor;
import com.baeldung.javaxval.container.validation.Profile;

View File

@ -2,8 +2,8 @@ package com.baeldung.javaxval.enums;
import java.util.Arrays;
import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import jakarta.validation.ConstraintValidator;
import jakarta.validation.ConstraintValidatorContext;
import com.baeldung.javaxval.enums.constraints.CustomerTypeSubset;
import com.baeldung.javaxval.enums.demo.CustomerType;

View File

@ -4,8 +4,8 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;
import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import jakarta.validation.ConstraintValidator;
import jakarta.validation.ConstraintValidatorContext;
import com.baeldung.javaxval.enums.constraints.EnumNamePattern;

View File

@ -3,8 +3,8 @@ package com.baeldung.javaxval.enums;
import java.lang.annotation.Annotation;
import java.util.Arrays;
import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import jakarta.validation.ConstraintValidator;
import jakarta.validation.ConstraintValidatorContext;
public abstract class EnumSubSetValidator<T extends Annotation, U> implements ConstraintValidator<T, U> {
private U[] subset;

View File

@ -4,8 +4,8 @@ import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import jakarta.validation.ConstraintValidator;
import jakarta.validation.ConstraintValidatorContext;
import com.baeldung.javaxval.enums.constraints.ValueOfEnum;

View File

@ -12,8 +12,8 @@ import java.lang.annotation.Documented;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
import javax.validation.Constraint;
import javax.validation.Payload;
import jakarta.validation.Constraint;
import jakarta.validation.Payload;
import com.baeldung.javaxval.enums.CustomerTypeSubSetValidator;
import com.baeldung.javaxval.enums.demo.CustomerType;

View File

@ -12,8 +12,8 @@ import java.lang.annotation.Documented;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
import javax.validation.Constraint;
import javax.validation.Payload;
import jakarta.validation.Constraint;
import jakarta.validation.Payload;
import com.baeldung.javaxval.enums.EnumNamePatternValidator;

View File

@ -12,8 +12,8 @@ import java.lang.annotation.Documented;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
import javax.validation.Constraint;
import javax.validation.Payload;
import jakarta.validation.Constraint;
import jakarta.validation.Payload;
import com.baeldung.javaxval.enums.ValueOfEnumValidator;

View File

@ -1,6 +1,6 @@
package com.baeldung.javaxval.enums.demo;
import javax.validation.constraints.NotNull;
import jakarta.validation.constraints.NotNull;
import com.baeldung.javaxval.enums.constraints.CustomerTypeSubset;
import com.baeldung.javaxval.enums.constraints.EnumNamePattern;

View File

@ -1,7 +1,7 @@
package com.baeldung.javaxval.javabeanconstraints.application;
import javax.validation.Validation;
import javax.validation.Validator;
import jakarta.validation.Validation;
import jakarta.validation.Validator;
import com.baeldung.javaxval.javabeanconstraints.entities.UserNotBlank;

View File

@ -1,6 +1,6 @@
package com.baeldung.javaxval.javabeanconstraints.entities;
import javax.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotBlank;
public class UserNotBlank {

View File

@ -1,6 +1,6 @@
package com.baeldung.javaxval.javabeanconstraints.entities;
import javax.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotEmpty;
public class UserNotEmpty {

View File

@ -1,6 +1,6 @@
package com.baeldung.javaxval.javabeanconstraints.entities;
import javax.validation.constraints.NotNull;
import jakarta.validation.constraints.NotNull;
public class UserNotNull {

View File

@ -1,6 +1,6 @@
package com.baeldung.javaxval.validationgroup;
import javax.validation.GroupSequence;
import jakarta.validation.GroupSequence;
@GroupSequence({ BasicInfo.class, AdvanceInfo.class })
public interface CompleteInfo {

View File

@ -1,7 +1,7 @@
package com.baeldung.javaxval.validationgroup;
import javax.validation.constraints.Email;
import javax.validation.constraints.NotBlank;
import jakarta.validation.constraints.Email;
import jakarta.validation.constraints.NotBlank;
public class RegistrationForm {
@NotBlank(groups = BasicInfo.class)

View File

@ -6,10 +6,10 @@ import java.time.LocalDate;
import java.util.Collections;
import java.util.Set;
import javax.validation.ConstraintViolation;
import javax.validation.Validation;
import javax.validation.Validator;
import javax.validation.ValidatorFactory;
import jakarta.validation.ConstraintViolation;
import jakarta.validation.Validation;
import jakarta.validation.Validator;
import jakarta.validation.ValidatorFactory;
import org.junit.Before;
import org.junit.Test;

View File

@ -4,9 +4,9 @@ import com.baeldung.javaxval.LocaleAwareUnitTest;
import org.junit.BeforeClass;
import org.junit.Test;
import javax.validation.ConstraintViolation;
import javax.validation.Validation;
import javax.validation.Validator;
import jakarta.validation.ConstraintViolation;
import jakarta.validation.Validation;
import jakarta.validation.Validator;
import java.math.BigDecimal;
import java.util.Set;

View File

@ -5,11 +5,11 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy;
import java.util.Set;
import javax.validation.ConstraintViolation;
import javax.validation.ConstraintViolationException;
import javax.validation.Validation;
import javax.validation.Validator;
import javax.validation.ValidatorFactory;
import jakarta.validation.ConstraintViolation;
import jakarta.validation.ConstraintViolationException;
import jakarta.validation.Validation;
import jakarta.validation.Validator;
import jakarta.validation.ValidatorFactory;
import org.junit.Before;
import org.junit.Test;

View File

@ -6,10 +6,10 @@ import java.util.Collections;
import java.util.OptionalInt;
import java.util.Set;
import javax.validation.ConstraintViolation;
import javax.validation.Validation;
import javax.validation.Validator;
import javax.validation.ValidatorFactory;
import jakarta.validation.ConstraintViolation;
import jakarta.validation.Validation;
import jakarta.validation.Validator;
import jakarta.validation.ValidatorFactory;
import com.baeldung.javaxval.container.validation.valueextractors.ProfileValueExtractor;
import org.junit.Before;

View File

@ -4,9 +4,9 @@ import static org.assertj.core.api.Assertions.assertThat;
import java.util.Set;
import javax.validation.ConstraintViolation;
import javax.validation.Validation;
import javax.validation.Validator;
import jakarta.validation.ConstraintViolation;
import jakarta.validation.Validation;
import jakarta.validation.Validator;
import org.junit.BeforeClass;
import org.junit.Test;

View File

@ -6,9 +6,9 @@ import static org.assertj.core.api.Assertions.assertThat;
import java.util.Set;
import javax.validation.ConstraintViolation;
import javax.validation.Validation;
import javax.validation.Validator;
import jakarta.validation.ConstraintViolation;
import jakarta.validation.Validation;
import jakarta.validation.Validator;
import org.junit.BeforeClass;
import org.junit.Test;

View File

@ -4,9 +4,9 @@ import static org.assertj.core.api.Assertions.assertThat;
import java.util.Set;
import javax.validation.ConstraintViolation;
import javax.validation.Validation;
import javax.validation.Validator;
import jakarta.validation.ConstraintViolation;
import jakarta.validation.Validation;
import jakarta.validation.Validator;
import org.junit.BeforeClass;
import org.junit.Test;

View File

@ -5,9 +5,9 @@ import static org.assertj.core.api.Assertions.assertThat;
import java.util.Set;
import java.util.function.Predicate;
import javax.validation.ConstraintViolation;
import javax.validation.Validation;
import javax.validation.Validator;
import jakarta.validation.ConstraintViolation;
import jakarta.validation.Validation;
import jakarta.validation.Validator;
import org.junit.BeforeClass;
import org.junit.Test;

View File

@ -4,9 +4,9 @@ import static org.assertj.core.api.Assertions.assertThat;
import java.util.Set;
import javax.validation.ConstraintViolation;
import javax.validation.Validation;
import javax.validation.Validator;
import jakarta.validation.ConstraintViolation;
import jakarta.validation.Validation;
import jakarta.validation.Validator;
import com.baeldung.javaxval.javabeanconstraints.entities.UserNotBlank;
import org.junit.BeforeClass;

View File

@ -4,9 +4,9 @@ import static org.assertj.core.api.Assertions.assertThat;
import java.util.Set;
import javax.validation.ConstraintViolation;
import javax.validation.Validation;
import javax.validation.Validator;
import jakarta.validation.ConstraintViolation;
import jakarta.validation.Validation;
import jakarta.validation.Validator;
import com.baeldung.javaxval.javabeanconstraints.entities.UserNotEmpty;
import org.junit.BeforeClass;

View File

@ -4,9 +4,9 @@ import static org.assertj.core.api.Assertions.assertThat;
import java.util.Set;
import javax.validation.ConstraintViolation;
import javax.validation.Validation;
import javax.validation.Validator;
import jakarta.validation.ConstraintViolation;
import jakarta.validation.Validation;
import jakarta.validation.Validator;
import com.baeldung.javaxval.javabeanconstraints.entities.UserNotNull;
import org.junit.BeforeClass;

View File

@ -4,9 +4,9 @@ import static org.assertj.core.api.Assertions.assertThat;
import java.util.Set;
import javax.validation.ConstraintViolation;
import javax.validation.Validation;
import javax.validation.Validator;
import jakarta.validation.ConstraintViolation;
import jakarta.validation.Validation;
import jakarta.validation.Validator;
import org.junit.BeforeClass;
import org.junit.Test;