I'm upgrading a project from 2.2.10 to 2.3.4 and encountered the following behavior change in our integration tests. We have a RestController with a @Valid annotation on the body. In 2.2 we see an errors property returned when sending in an invalid request. As of 2.3 we no longer get the errors property.

Sample Code:

@RestController
class MyController {
    @PutMapping("/my/{id}")
    fun updateMy(@PathVariable id: String, @RequestBody @Valid body: MyBody): ResponseEntity<Unit> {
        return ResponseEntity(HttpStatus.NO_CONTENT)
    }
}

data class MyBody(
    @get:Range(min = 1L, max = 12L, message = "This field should be between 1 and 12.")
    val bodyType: Int
)

Hitting PUT /my/1 --data-raw '{"bodyType": 0}' in Spring 2.2.10 returns:

{
    "timestamp": "2020-09-20T14:33:54.429+0000",
    "status": 400,
    "error": "Bad Request",
    "errors": [
        {
            "codes": [
                "Range.body.bodyType",
                "Range.bodyType",
                "Range.int",
                "Range"
            ],
            "arguments": [
                {
                    "codes": [
                        "body.bodyType",
                        "bodyType"
                    ],
                    "arguments": null,
                    "defaultMessage": "bodyType",
                    "code": "bodyType"
                },
                12,
                1
            ],
            "defaultMessage": "This field should be between 1 and 12.",
            "objectName": "body",
            "field": "bodyType",
            "rejectedValue": 0,
            "bindingFailure": false,
            "code": "Range"
        }
    ],
    "message": "Validation failed for object='body'. Error count: 1",
    "path": "/my/1"
}

Hitting PUT /my/1 --data-raw '{"bodyType": 0}' in Spring 2.3.0 and 2.3.4 returns:

{
    "timestamp": "2020-09-20T14:17:27.041+00:00",
    "status": 400,
    "error": "Bad Request",
    "message": "",
    "path": "/my/1"
}

I saw that the validation starter package is no longer included by default in Spring Boot 2.3, and we added it, but the errors properties do not come back. I looked through the Release Notes and did not see this behavior called out and I am opening a bug.

Happy to create a sample repo to reproduce if required.

Also, per the documentation reference I did also try adding @Validated to the data class, but no behavior change occurred.

Comment From: philwebb

With Spring Boot 2.3 we changed content that's displayed on the default error page. It's covered in this section of the release notes.

If you want the old behavior, you can add the following to your application.properties

server.error.include-message=always
server.error.include-binding-errors=always

If that doesn't work, please provide a sample application and we'll take another look.

Comment From: busches

@philwebb thanks for the information, that was what I needed. I would not have considered an API response to fall under default error page and must have skimmed over it. Thanks again.