[Java] Where is the implementation class of annotation that exists in Bean Validation?

background

When implementing validation in Java or Spring, you may use Bean Validation such as @ NotNull or @NotBlank.

When I was implementing, I wondered what the implementation class associated with these annotations was, so I looked at the source code, but the validatedBy of @ Constraint was blank. ..

Take the NotBlank annotation [^ 1] in the javax.validation.constraints package as an example.

NotBlank.java


@Documented
@Constraint(validatedBy = { }) //The class in which the contents of validation are written is not specified by ←
@Target({ METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER, TYPE_USE })
@Retention(RUNTIME)
@Repeatable(List.class)
public @interface NotBlank {

	String message() default "{javax.validation.constraints.NotBlank.message}";

	Class<?>[] groups() default { };

	Class<? extends Payload>[] payload() default { };

	/**
	 * Defines several {@code @NotBlank} constraints on the same element.
	 *
	 * @see NotBlank
	 */
	@Target({ METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER, TYPE_USE })
	@Retention(RUNTIME)
	@Documented
	public @interface List {
		NotBlank[] value();
	}
}

This time, I investigated the class that is associated with the location of the implementation result of this annotation.

Survey results

When I searched on Google, the same question was asked on stackoverflow at here, and I was able to find out the implementation class. ..

That is here org NotBlankValidator class under .hibernate.validator.internal.constraintvalidators.bv.

From this, we can see that the annotation and its implementation class are not in the same library, but in different libraries.

Also, the class that links these exists in the same library as the implementation class, and [here](https://github.com/hibernate/hibernate-validator/blob/db7ae586508add6491f1443c8ab4e770d7cb2c20/engine/src/main/java/org It turned out that it is linked by the ConstraintHelper class under org.hibernate.validator.internal.metadata.core of /hibernate/validator/internal/metadata/core/ConstraintHelper.java).

Summary

This time, I found that the annotation implementation class that exists in Bean Validation's javax.validation.constraints exists under org.hibernate.validator.internal.constraintvalidators.bv.

We also found that these classes are linked by the ConstraintHelper class under org.hibernate.validator.internal.metadata.core.

However, I don't understand why annotations and implementation classes bother to exist in different libraries. It seems that the relationship between Bean Validation and Hibernate is involved, but is it like separating the interface and implementation in consideration of extensibility?

If anyone knows about this point, I would appreciate it if you could tell me.

Until the end Thank you for reading.

References

Site that triggered the solution

NotBlankValidator.java

ConstraintHelper.java

Recommended Posts

[Java] Where is the implementation class of annotation that exists in Bean Validation?
This and that of the implementation of date judgment within the period in Java
[Java] Is it unnecessary to check "identity" in the implementation of the equals () method?
Summarize the additional elements of the Optional class in Java 9
The story that .java is also built in Unity 2018
[Spring Boot] The story that the bean of the class with ConfigurationProperties annotation was not found
Implementation of gzip in java
Implementation of tri-tree in Java
Determine that the value is a multiple of 〇 in Ruby
[Rails] Where to be careful in the description of validation
Where is the Java LocalDateTime.now () timezone?
Implementation of like function in Java
Mechanism and characteristics of Collection implementation class often used in Java
The milliseconds to set in /lib/calendars.properties of Java jre is UTC
Examine the list of timezone IDs available in the Java ZoneId class
When the bean class name is duplicated
What is a class in Java language (3 /?)
Implementation of DBlayer in Java (RDB, MySQL)
Get the result of POST in Java
Code of the part where server.servlet.session.timeout is set in spring.session.timeout in spring-boot2 system
What is a class in Java language (1 /?)
What is a class in Java language (2 /?)
What is the main method in Java?
Where is the home directory location of "Ubuntu"? (Solved in the comment section)
Where the follow function implementation is stuck
Error when the member of Entity class used in SpringWebFlux is final
Sample program that returns the hash value of a file in Java
From Java9, the constructor of the class corresponding to primitive types is deprecated.
The story of writing Java in Emacs
Review of "strange Java" and Java knowledge that is often forgotten in Java Bronze
[Rails] Implementation of validation that maintains uniqueness
[Java] Implement a function that uses a class implemented in the Builder pattern
Code that deletes all files of the specified prefix in AWS S3 (Java)
Cause of is not visible when calling a method of another class in java
[Java] Calculate the day of the week from the date (Calendar class is not used)
Correspondence of the part where Authentication # getDetails is done in the unit test of spring-security
[Java] Handling of JavaBeans in the method chain
The story of making ordinary Othello in Java
About the idea of anonymous classes in Java
The order of Java method modifiers is fixed
Measure the size of a folder in Java
Feel the passage of time even in Java
A quick review of Java learned in class
[Java] Something is displayed as "-0.0" in the output
Import files of the same hierarchy in Java
General-purpose StringConverter class that utilizes generics in Java8
First touch of the Files class (or Java 8)
[Ruby on Rails] Implementation of validation that works only when the conditions are met
How to get the class name of the argument of LoggerFactory.getLogger when using SLF4J in Java
Java General-purpose method that retrieves only the differences between the properties of objects of the same class
Java Error Handling Basics-The story that catch is only picked up in the foreground
Get the URL of the HTTP redirect destination in Java
In Time.strptime,% j (total date of the year) is
A quick review of Java learned in class part4
Return the execution result of Service class in ServiceResponse class
The comparison of enums is ==, and equals is good [Java]
Write a class that can be ordered in Java
Get the name of the test case in the JUnit test class
Which is better, Kotlin or Java in the future?
Browse class objects in Kotlin (instead of Java class name.class)
[Java] Get the file in the jar regardless of the environment