#Validate Request Body and Parameter in Spring Boot
31 messages · Page 1 of 1 (latest)
⌛ This post has been reserved for your question.
Hey @unique walrus! Please use
/closeor theClose Postbutton above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
What exactly is the problem?
@PostMapping("/register")
public ResponseEntity<?> Register(@RequestBody @Valid CreateUserDto createUserDto, BindingResult bindingResult) {
if (bindingResult.hasErrors())
return ResponseEntity
.badRequest()
.body(new MessageResponse(bindingResult.getAllErrors().toString()));
return authService.createUserFromRegister(createUserDto);
}
looks fine
but validation isnot working.
What happens?
This doesn't tell me what happens
You are mixing Jakarta EE and Java EE
if you are using Spring Boot 3, use jakarta.validation imports
and remove all javax stuff from your dependencies
so javax library is not worked?
In a Jakarta EE project, javax things don't work
don't mix them
Jakarta EE replaced Java EE
If you have Spring Boot 3, you hava Jakarta EE
don't use javax and use jakarta.validation. right?
yes
@NotEmpty is for strings
I guess you want @NotNull or similar
@summer anvil
thank you very much.
If you are finished with your post, please close it.
If you are not, please ignore this message.
Note that you will not be able to send further messages here after this post have been closed but you will be able to create new posts.