spring-projects-experimental/spring-fu

notNull validation constraint is not working in samples

AntipovAndrey opened this issue · 0 comments

In kofu-*-validation samples the notNull constraint has no effect since the validated field is already of non-nullable type String.

E.g.:

POST  http://localhost:8181/api/user
Content-Type: application/json

{
  "login": null,
  "firstname": "",
  "lastname": ""
}

Response:

POST http://localhost:8181/api/user

HTTP/1.1 400 Bad Request
Content-Type: application/json
Content-Length: 161

{
  "timestamp": "2019-11-15T07:54:14.452+0000",
  "path": "/api/user",
  "status": 400,
  "error": "Bad Request",
  "message": "Failed to read HTTP message",
  "requestId": "47b1c49f"
}

Response code: 400 (Bad Request); Time: 69ms; Content length: 161 bytes

If I make the login property to be of type String?, then validation constraints will be activated properly, and for the same request it'll response with validation messages:

POST http://localhost:8181/api/user

HTTP/1.1 400 Bad Request
Content-Type: application/json
Content-Length: 318

{
  "details": [
    {
      "args": [
        "login",
        null
      ],
      "defaultMessage": "\"login\" must not be null",
      "key": "object.notNull"
    },
    {
      "args": [
        "firstname",
        ""
      ],
      "defaultMessage": "\"firstname\" must not be blank",
      "key": "charSequence.notBlank"
    },
    {
      "args": [
        "lastname",
        ""
      ],
      "defaultMessage": "\"lastname\" must not be blank",
      "key": "charSequence.notBlank"
    }
  ]
}

Response code: 400 (Bad Request); Time: 783ms; Content length: 318 bytes

That's happening because the request fails during deserialization never reaches the validation logic