Skip to content

Latest commit

 

History

44 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Micronaut Quickstart Validation

Sample Micronaut project demonstrating how to use validation with Jakarta Validation API.

This is a direct translation of Quarkus' validation-quickstart project.

Key differences

  • In Micronaut one must use @io.micronaut.validation.Validated to be able to activate the validation; merely using @jakarta.validation.Valid is not enough. @Validated had to be used on both BookResource controller and BookService.
  • The Restassured tests methods must use an argument RequestSpecification otherwise the library won't be able to connect to the test server.
  • The test method BookResourceTest#testBookWithoutTitleEndPointValidation had to be adjusted to account for the error response:
{
   "message": "Bad Request",
   "_links": {
        "self": {
          "href": "/books/end-point-method-validation",
          "templated": false
        }
  },
  "_embedded": {
     "errors": [
       {
          "message": "book.title: Title cannot be blank"
       }
    ]
  }
}

Contrast this with Quarkus' simpler response:

{
    "title": "Constraint Violation",
    "status": 400,
    "violations": [
        {
            "field": "tryMeEndPointMethodValidation.book.title",
            "message": "Title cannot be blank"
        }
    ]
}

Micronaut 4.2.3 Documentation


Feature micronaut-aot documentation

Feature hibernate-validator documentation

Feature http-client documentation

Feature hamcrest documentation

Feature maven-enforcer-plugin documentation

About

Micronaut Micronaut Validation Application

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages