Spring Boot - JSR 303 - The Right Way To Validate Objects

preview_player
Показать описание

🎁 🚀 COUPON Code: EARLYBIRD20

Don't Forget to
===========================================
💯 Subscribe to the youtube channel

Table of content

00:00 Introduction
02:12 Validation process
08:11 Bootstrapping the application
10:43 Test the App
13:29 How to validate objects
14:39 Adding the dependency
15:29 Validate using @Valid annotation
22:40 Implement the validator
34:03 Testing the changes
36:57 Make the validator Generic

#spring #learning #springboot #springtutorial #springsecurity #development #java #arraylist #linkedlist #springdatajpa #querybuilder #aliboucoding #alibou #validation
Рекомендации по теме
Комментарии
Автор

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 <T> void validate (T t){...}`

This way you can validate different types of objects with a single validator instance

cdev
Автор

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.

lts
Автор

Couldn't find anything better about manual validation in Spring without using @Valid. Cheers!

dotherap
Автор

Great video - clearly explained as ever. Did you create the the follow-up video btw, as promised at the end?

johnarnett
Автор

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.

pranaypaul
Автор

Very helpful thanks for helping me understand custom validation!

earlpadron
Автор

Your response sends back a 2xx http status on validation violations which is not good.

debkr
Автор

Kindly provide how we can configure error messages from application.properties file. I have tried many approaches but no luck.

nikhilraghav
Автор

@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 ?

gouravsharma-loot
Автор

Hello, can you create a video on Unit Testing mainly on integration testing for spring boot!!
Thanks

shakamuhammed
Автор

can anyone help me for validate xml request body against xsd in spring boot application

tradeinfo
Автор

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

erichhc
Автор

Awesome job!! Thank you! Continuation is hard to find :(

MrSMSASS
Автор

May i know the release date of continuation.

ArunKumar-trql
Автор

Awesome course Sir, well explained baraka allaho fik, can you provide source code please ?

xkzn
Автор

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

emersontavera
Автор

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

AA-nuht
Автор

Hi Ali, I have one doubts when u should use spring boot starter validation or hibernate validator? can you explain to me?

ytcoqqw
Автор

I don't see the follow up of this video in the playlist :(

michaelcapone
Автор

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

zqgAFf