You could just try to convert to the type. I would recommend that you always have a schema to validate against. Jackson has a module to create a JSON schema from annotations on classes.
Hi Mike, I have observed one issue with this code. I am taking one model class(dto) as my controller class request(using @RequestBody Some ClassName request) and calling the jsonvalidator service. after calling the jsonvalidator service i am converting my incoming request to string using the ObjectMapper writeValueAsString method. after that i have added all the logic which you have written but its failing to validate my json under the rules i have provided in schema. Its not validating the type of data and its format. Pls help me on this. pls let me know if any details required for the above explanation.
Read the Jackson documentation. You need some annotations on your model. And maybe you need 2 models. One for serializing and one for deserializing. It depends on the usecase.
Thanks, Mike for a great tutorial. Can we validate (using this library) the JSON which contains a list of objects and get the positions for invalid ones?
Hi Mike, Just wanted to know how this is different from the default validation provided by spring boot. I mean we can use @NotNull or such annotation by default in spring boot beans. Is there any additional functionality json schema brings in?
With the default spring validation you just get an exception if the data don't match. Here you can apply extra rules like name should be between 10 and 200 characters.
Great video! Please explain how to validate json payload using annotations.
You could just try to convert to the type. I would recommend that you always have a schema to validate against. Jackson has a module to create a JSON schema from annotations on classes.
Thanks Mike!! Great job...
Thank you very much for watching and commenting. :-)
Thank you so much for this video Sir
Most welcome
Nice one, really I love it ..... :)
Thank you! Cheers! Say more :)
Thank you very much. Its very much informative.
Thx for watching :)
@@MikesTechCorner Hi Mike,
1) Is there any way to get custom error messages?
2) Will it support multilingual?
Thanks, very good tutorial
Hi Mike,
I have observed one issue with this code.
I am taking one model class(dto) as my controller class request(using @RequestBody Some ClassName request)
and calling the jsonvalidator service.
after calling the jsonvalidator service i am converting my incoming request to string using the ObjectMapper writeValueAsString method.
after that i have added all the logic which you have written but its failing to validate my json under the rules i have provided in schema.
Its not validating the type of data and its format.
Pls help me on this.
pls let me know if any details required for the above explanation.
Read the Jackson documentation. You need some annotations on your model. And maybe you need 2 models. One for serializing and one for deserializing. It depends on the usecase.
Thanks, Mike for a great tutorial. Can we validate (using this library) the JSON which contains a list of objects and get the positions for invalid ones?
I'm not sure how detailed the error message is, but you will get a description of what was wrong with the json.
Hi Mike,
Just wanted to know how this is different from the default validation provided by spring boot. I mean we can use @NotNull or such annotation by default in spring boot beans. Is there any additional functionality json schema brings in?
With the default spring validation you just get an exception if the data don't match. Here you can apply extra rules like name should be between 10 and 200 characters.
@@MikesTechCornerin sprint boot validation you can do this as well
awesome tutorial, thank you!!!
You are welcome. Thank you for commenting!