Skip to content

Latest commit

 

History

History
77 lines (56 loc) · 2.52 KB

README.md

File metadata and controls

77 lines (56 loc) · 2.52 KB

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