Monday 20 February 2023

Bean validations in Micronaut

 

Micronaut support bean validation. To use bean validation in your services, you should use below dependency.

 

<dependency>
	<groupId>io.micronaut</groupId>
	<artifactId>micronaut-validation</artifactId>
	<version>${micronaut.version}</version>
</dependency>

 

Is Micronaut validation module compliant with ‘Jakarta Bean Validation specification’?

At the time of writing this post, Micronaut validation module is not fully compliant with ‘Jakarta Bean Validation specification’. Following features are unsupported at this time:

 

a.   Annotations on generic argument types, since only the Java language supports this feature.

b.   Any interaction with the constraint metadata API, since Micronaut uses compile-time generated metadata.

c.    XML-based configuration

d.   Instead of using javax.validation.ConstraintValidator, use ConstraintValidator (io.micronaut.validation.validator.constraints.ConstraintValidator) to define custom constraints, which supports validating annotations at compile time.

 

Micronaut’s implementation includes the following benefits:

 

a.   Reflection and Runtime Proxy free validation, resulting in reduced memory consumption

b.   Smaller JAR size since Hibernate Validator adds another 1.4MB

c.    Faster startup since Hibernate Validator adds 200ms+ startup overhead

d.   Configurability via Annotation Metadata

e.   Support for Reactive Bean Validation

f.     Support for validating the source AST at compile time

g.   Automatic compatibility with GraalVM native without additional configuration

 

What If my application needs to be compliant with ‘Jakarta Bean Validation specification’?

Use micronaut-hibernate-validator module instead of micronaut-validation module.

 

 

References

https://beanvalidation.org/2.0/spec/

Previous                                                    Next                                                    Home

No comments:

Post a Comment