Great video ! your content is very useful. Thank you! Just to mention: You can make generic just the 'validate' method and not the full ObjectValidator class `public void validate (T t){...}` This way you can validate different types of objects with a single validator instance
I think the second way to make method validate generic is to change the type of the argument to type Object. Thank you very much, you always create new content that is new and different.
Great basic core validation concept explained!! where's the next part? and is it still the best practice in industry or something better has come up by now? Thank you.
@BoualiAli in the end you said in the next video you will be showing how we can even remove the validator check in the service layer, but i was not able to find the next video can i have the link ?
Hello, thanks for your videos, they are really helpful and insightful, but I have a question: I found on the documention that there is an interface 'validator' that we can implement and override the support() and validate() methods. In the controller class, we can annotate one method with the @InitBinder annotation and add the validator using the add method from the WebDataBinder which is injected as a parameter to the method. Now if an object needs to be validated using the @Valid annotation, the WebDataBinder is going to look for an implementation that supports the type of data in question, if exists, performs validation and the errors are loading in the BindingResult parameter which is accesible in the endpoint that requested the validation After this, we can handle the error and return a responseEntity to the client But my question is basically comparing your approach to the one I found in the documentation, which way is more commonly found in production code? I request the validation in the controller layer, but you do it in the service layer I've been learning spring for 2 months, and the whole thing is about to make click in my head :3 feels good, but also raises many questions xd thanks in advance, sorry for the long comment
Hello, thanks for the nice feedback and happy that you learn from my channel. Actually there are many ways to validate objects including the one mentioned by implementing the interface your own. Also you can just use the @Valid annotation on the object you want to validate in the controller and the catch the exception that will be thrown and return a proper response to the user. You can also follow my way of validation if you have for example extra logic that you need to implement while / after validating your objects. In production (based on my experience) I saw all of them tbh, so it really hard to tell which one is the most used in production. So it always depends on the use cases of your application / team I hope this was helpful
Excellent explanation Boali ali 😎😎 About that validation that I didn't know (Y), I have a query. Is it also included as a good practice to use controllerAdice? to handle validations ? * Greetings from Peru
Hi I never approach this type of content before , so I wonder does it work as well in springboot 3.0 or above ? or we use different strategy to do this validation
@@BoualiAli that will be awesome , will there be a follow-up video to do the validation which is commonly used in production ? I checked your other video ,it seems that so far it hasn't come out yet
Hello Ali, as always thank you for the content you're providing us. I just have one point which is a bit blurry to me. Is Greeting the entity or the DTO? Because I heard it's best to work on the DTOs not the Entities since those are the objects we'll recieve into our post method. Right? Please enlight me and Ramadan Moubarak
@@BoualiAli thanks man. Before spring boot 3.0, We were extending from ResponseEntityExceptionHandler and override its one the method (ResponseEntity handleMethodArgumentNotValid) this method handles the beans validation errors in globally. We don’t need to handle for every Java beans. It’s kind of generic one. But after spring boot 3.0 this method no longer there. @Override protected ResponseEntity handleMethodArgumentNotValid(MethodArgumentNotValidException ex, HttpHeaders headers, HttpStatus status, WebRequest request) { Map errors = new HashMap(); ex.getBindingResult().getAllErrors().forEach((objectError) -> { String fieldError = ((FieldError) objectError).getField(); String message = objectError.getDefaultMessage(); errors.put(fieldError, message); }); return new ResponseEntity(errors, HttpStatus.BAD_REQUEST); } Is any alternative for this? We are waiting from you!!!
COUPON Code: *EARLYBIRD20* => Spring Data J PA course: aliboucoding.com/p/the-full-guide-to-master-spring-boot-data-jpa
Couldn't find anything better about manual validation in Spring without using @Valid. Cheers!
My pleasure!
Great video ! your content is very useful. Thank you!
Just to mention:
You can make generic just the 'validate' method and not the full ObjectValidator class
`public void validate (T t){...}`
This way you can validate different types of objects with a single validator instance
Totally true.
Thank you for hi-lighting this
I think the second way to make method validate generic is to change the type of the argument to type Object.
Thank you very much, you always create new content that is new and different.
Thank you for your feedback
Objects are not required (generally speaking) because you need to cast them each time you need to access custom dat
Very helpful thanks for helping me understand custom validation!
Happy to help!
so happy i found this channel
Thank you, Ya Abu Ali.
My pleasure
Great video - clearly explained as ever. Did you create the the follow-up video btw, as promised at the end?
I did!
check the playlists
@@BoualiAli I could not find the link for the follow up video, would you please share the link here ?
Great basic core validation concept explained!! where's the next part? and is it still the best practice in industry or something better has come up by now? Thank you.
Very well explained I must say.
Thank you for your feedback
Cool, it's amazing.
Thank you! Cheers!
Great content. Really useful.
Happy you enjoyed it
@BoualiAli in the end you said in the next video you will be showing how we can even remove the validator check in the service layer, but i was not able to find the next video
can i have the link ?
Check the Full spring boot course (8 hours) and you will have your answer there
can anyone help me for validate xml request body against xsd in spring boot application
Post your issue in the discord server and you will get help there
Kindly provide how we can configure error messages from application.properties file. I have tried many approaches but no luck.
Hello, can you create a video on Unit Testing mainly on integration testing for spring boot!!
Thanks
I already have one, check the playlist
Good stuff bro:)
Glad you enjoyed
Your response sends back a 2xx http status on validation violations which is not good.
Thank you 🥰
Hi Ali, I have one doubts when u should use spring boot starter validation or hibernate validator? can you explain to me?
check the ultimate guide and you will find your answer there
Awesome job!! Thank you! Continuation is hard to find :(
Check the playlist.
@@BoualiAli Thank you! it’s in exception handling
May i know the release date of continuation.
Check the playlist for all the videos
Hello, thanks for your videos, they are really helpful and insightful, but I have a question:
I found on the documention that there is an interface 'validator' that we can implement and override the support() and validate() methods.
In the controller class, we can annotate one method with the @InitBinder annotation and add the validator using the add method from the WebDataBinder which is injected as a parameter to the method.
Now if an object needs to be validated using the @Valid annotation, the WebDataBinder is going to look for an implementation that supports the type of data in question, if exists, performs validation and the errors are loading in the BindingResult parameter which is accesible in the endpoint that requested the validation
After this, we can handle the error and return a responseEntity to the client
But my question is basically comparing your approach to the one I found in the documentation, which way is more commonly found in production code? I request the validation in the controller layer, but you do it in the service layer
I've been learning spring for 2 months, and the whole thing is about to make click in my head :3 feels good, but also raises many questions xd thanks in advance, sorry for the long comment
Hello, thanks for the nice feedback and happy that you learn from my channel.
Actually there are many ways to validate objects including the one mentioned by implementing the interface your own.
Also you can just use the @Valid annotation on the object you want to validate in the controller and the catch the exception that will be thrown and return a proper response to the user.
You can also follow my way of validation if you have for example extra logic that you need to implement while / after validating your objects.
In production (based on my experience) I saw all of them tbh, so it really hard to tell which one is the most used in production. So it always depends on the use cases of your application / team
I hope this was helpful
I don't see the follow up of this video in the playlist :(
In the same playlist
Excellent explanation Boali ali 😎😎
About that validation that I didn't know (Y), I have a query. Is it also included as a good practice to use controllerAdice? to handle validations ?
* Greetings from Peru
The answer is coming next week 😁😁
Join the discord and exchange with people
Someone pls help i m not able to import javax.Validation.Validation
Which spring version you use?
@@BoualiAli I m using 3.0.0
Hi I never approach this type of content before , so I wonder does it work as well in springboot 3.0 or above ? or we use different strategy to do this validation
It works the same with spring 3
@@BoualiAli that will be awesome , will there be a follow-up video to do the validation which is commonly used in production ? I checked your other video ,it seems that so far it hasn't come out yet
@@zqgAFf can you explain me what you mean by used in production?
@@BoualiAli no worry thank u so much for the effort I hope I can see the role based version I just saw the refresh token version
@@zqgAFf I will create a video for that.
It will published soon
Hello Ali, as always thank you for the content you're providing us. I just have one point which is a bit blurry to me. Is Greeting the entity or the DTO? Because I heard it's best to work on the DTOs not the Entities since those are the objects we'll recieve into our post method. Right?
Please enlight me and Ramadan Moubarak
Ramadan Kareem.
Greeting is the DTO, you should validate the DTO
@@BoualiAli yes I just figured it out by rewatching the video 😊 I will now watch the second video
@@AA-nu7ht great 👍
Can’t we use Restcontrolleradvice?
Coming in few days
Working on it
@@BoualiAli thanks man. Before spring boot 3.0, We were extending from ResponseEntityExceptionHandler and override its one the method (ResponseEntity handleMethodArgumentNotValid) this method handles the beans validation errors in globally. We don’t need to handle for every Java beans. It’s kind of generic one. But after spring boot 3.0 this method no longer there.
@Override
protected ResponseEntity handleMethodArgumentNotValid(MethodArgumentNotValidException ex, HttpHeaders headers, HttpStatus status, WebRequest request) {
Map errors = new HashMap();
ex.getBindingResult().getAllErrors().forEach((objectError) -> {
String fieldError = ((FieldError) objectError).getField();
String message = objectError.getDefaultMessage();
errors.put(fieldError, message);
});
return new ResponseEntity(errors, HttpStatus.BAD_REQUEST);
}
Is any alternative for this? We are waiting from you!!!
@@vageeshanvageesh5583 it much easier than that.
You will see in few days
@@BoualiAli Thanks dude, We are waiting..
Awesome course Sir ,well explained baraka allaho fik, can you provide source code please ?
Happy you liked it.
The source code is in my github profile
where is the part 2 sir ?
check the playlist
Ok, for everyone looking for the next video that improve the code of this one: ruclips.net/video/MhZl4YikM20/видео.html
Thanks for sharing
top
thank you
Kinda "fat" way. You can simply create an exception holder class with @ControllerAdvice annotation and extend ResponseEntityExceptionHandler.
Thanks for your comment.
Just check the playlist and you will get your answer 😇
@@BoualiAli nice, I just noticed you have a video about that, added 3 weeks ago. Great 🤩
@@sweets7092 which video please ? I can't find it.
@@princessazula8897 Search for "Spring Boot Exception Handling Made Easy".
Atleast tell from start .. whats in dto , dao , model pkgs .. how a beginner will learn you..bewakoof
I suppose @NotEmpty includes @NotNull already
Nope