I have a class:
class User(
var name: String
)
And a mapped post request:
@PostMapping("/user")
fun test(@Valid @RequestBody user: User) {
//...
}
What if a client will send a JSON of a user with name: null
? Will it be rejected by the MVC Validator or an exception will be throwed? Should I annotate name
with @NotNull
? Unfortunately, I cannot check that because only can write tests (it is not available to create User(null)
).
As I tested, @NotNull
doesn't affect on the MVC validation at all. You will only receive a WARN
message in console which is normal:
Failed to read HTTP message: org.springframework.http.converter.HttpMessageNotReadableException: Could not read document: Instantiation of...