15 Why you should avoid returning lists in APIs - Spring Boot Microservices Level 1

  Рет қаралды 217,606

Java Brains

Java Brains

Күн бұрын

Пікірлер: 81
@fancywatches837
@fancywatches837 5 жыл бұрын
Your explanation about not passing list as a parameter to the rest endpoint was golden! You are goldmine of knowledge
@eimaisklhros
@eimaisklhros 5 жыл бұрын
8:07 in the pop up window, go down-> Select None -> there's your empty constructor!! Kushik I want you to know that I got a job and 5th day on the job, I just study from this playlist to learn microservices bro! When you come to Greece for vacations I'll definitely buy you a beer! Thank you very much!!!
@PiyushShandilya
@PiyushShandilya 5 жыл бұрын
Koushik: "Isn't there a way to create a no argument constructor in intellij these days?" The de-select fields option: "Am I a joke to you?"
@stevend1070
@stevend1070 5 жыл бұрын
Piyush Shandilya there’s also select none lol
@sivarajamani6709
@sivarajamani6709 5 жыл бұрын
r u 9gager?
@rinkeshrohan
@rinkeshrohan 4 жыл бұрын
Ctrl + left click on selected object to deselect the object. ✌️
@vsk0208
@vsk0208 3 жыл бұрын
8:06 Click on Class name on top of field name and click Ok to create empty param constructor.
@bazar9000
@bazar9000 3 жыл бұрын
You can use Lombok and anottate your class with @NoArgsConstructor
@explorerfl007
@explorerfl007 5 жыл бұрын
@Koushik: You can use lombok api to have constructor/getter/setter/builder all done with annotations.
@StyleTrick
@StyleTrick 5 жыл бұрын
Hey Koushik, great tutorials on Spring! By the way, to create an empty constructor, choose the "Select None" option =)
@SMN_n1
@SMN_n1 5 жыл бұрын
U'r course ist the very best! Thanks again!!!
@rajugm9504
@rajugm9504 5 жыл бұрын
Teaching is like a spoon feeding thank you boss !! kudos to you :-)
@TheRickTuber
@TheRickTuber 5 жыл бұрын
You can use Rating[].class and then wrap your method in a Arrays.asList() instead of using ParameterizedTypes.
@SasidaranRajaram
@SasidaranRajaram 5 жыл бұрын
Any limitations in using this approach? Does this work for complex object structures as well? Thanks in advance!
@sharanrai4603
@sharanrai4603 4 жыл бұрын
@@SasidaranRajaram yes it does
@AshutoshSharma31
@AshutoshSharma31 5 жыл бұрын
8:08 select the option "Select none" to create an empty constructor.
@akhilkapoor5127
@akhilkapoor5127 5 жыл бұрын
yup
@sagarshekhar6296
@sagarshekhar6296 5 жыл бұрын
Koushik, ur videos are crystal clear and excellent...excellent.....excellent....:)
@aqibishaq308
@aqibishaq308 4 жыл бұрын
after watching level 1 15 videos lemme tell u i am your fan
@vsk0208
@vsk0208 3 жыл бұрын
8:06 Click on Class name on top of field name and click Ok to create empty param constructor.
@ronishpanjwani9241
@ronishpanjwani9241 3 жыл бұрын
Why do we need the empty Constructor
@haimmichalashvili8251
@haimmichalashvili8251 4 жыл бұрын
Hey Koushik, you can generate empty constructor with intellij by not choosing any of thr feilds in the window.
@KolomiecSergeyK
@KolomiecSergeyK 4 жыл бұрын
To create empty constructor go to class line (first line in popup) and just hit `enter+ctrl`
@cryptoeric24
@cryptoeric24 4 жыл бұрын
I used the UserRating wrapper but when it comes back from the api call the movie field is null but all the other fields are present. What is going on??? ex: coming back from rating service: RatingsList: [Rating{id=16, movie='sneakers', rating=5}, Rating{id=17, movie='nickolas nickleby', rating=5}], showing up in movie-catlog service: [Rating{id=16, movie='null', rating=5}, Rating{id=17, movie='null', rating=5}]
@letsrock7354
@letsrock7354 4 жыл бұрын
make sure all services are running, looks like somewhere you are getting null objects, for more send me the code at kuldeepdixit96@gmail.com . Dont forget to reply here when u send me the code.
@asheeshverma3305
@asheeshverma3305 Жыл бұрын
How to create empty constructor? Goto class where need to create empty constructor. below the class Cmd + N in MacBook then choose Constructor -> then Select class name instead of any properties.
@testcase2299
@testcase2299 3 жыл бұрын
sir i have a question we can call get api by restTemplate but what about post api.i need to call a api that expecting a object for example sav.how to pass object to api in different service
@adancastroharos9408
@adancastroharos9408 2 жыл бұрын
Thank you very much, this is very helpful
@hansmbua4343
@hansmbua4343 2 жыл бұрын
To create an empty constructor, I usually go to generate > constructor > unselect the parameters and click on "OK"
@hyperborean72
@hyperborean72 3 жыл бұрын
Very useful chapter, thank you
@anupamkumartejaswi9210
@anupamkumartejaswi9210 4 жыл бұрын
not sure why i got this at top of my search result for search saying "can not deserialize instance of out of start_array token" but when i watched till the end i got my answer.
@baibhavghimire3827
@baibhavghimire3827 4 жыл бұрын
I think if you guys understand Video-11 and this Video(15) nicely , Micro-services is a piece of cake..
@tiagovieira6653
@tiagovieira6653 3 жыл бұрын
Can't you send an array with ids as param... And only do a call to the database in service layer? Because that way there will Be a lot of calls to database, passing one id each time
@surbhigupta6367
@surbhigupta6367 2 жыл бұрын
Hi sir, In RatingService, where you have created a wrapper class (UserRating), will it be okay if we pass list in the userRatingconstructor and return the UserRating Object instead of calling the Set method and then return.
@rik2101986
@rik2101986 5 жыл бұрын
Hi I am getting error: com.fasterxml.jackson.exc.MismatchedException: Cannot deserialize instance of com.xyz.models.UserRating out of START_ARRAY token ar [Source: (PushbackInputStream);line:1,column:1] Please help.
@weitanglau162
@weitanglau162 4 жыл бұрын
Should we have a class or an interface as the return type?
@contactdi8426
@contactdi8426 2 жыл бұрын
Kuch nahi samjha,, but majjaa aaya :) Abhi bhut mehnat karne ki jarurat hai apun ko :)
@sambhajikale7338
@sambhajikale7338 2 жыл бұрын
How user additional field impact List return type not clear. If anyone is clear please clarify.
@anantsaxena6849
@anantsaxena6849 4 жыл бұрын
You are amazing sir ... Can you please post a video on stream apis.
@BanuKones
@BanuKones 4 жыл бұрын
Hi Koushik, I think you want to avoid using mouse and select none on the popup for empty constructor. You can use Up Arrow and Enter. (up arrow highlights class name and deselect the field)
@ilhammammadli4560
@ilhammammadli4560 2 жыл бұрын
event best way, just go on the class name with cursor(up or down), press ctrl+W(chose the class name-> alt+insert -> constructor ->TABx2->enter it creates empty constructor
@ilhammammadli4560
@ilhammammadli4560 2 жыл бұрын
to bring back project sidePanel - ALT+1 to create new class -> close right folder first -> up down arrows -> ALT+Insert
@potatosheep
@potatosheep 4 жыл бұрын
How do you test this?
@amritraj2303
@amritraj2303 5 жыл бұрын
Koushik..Thanks a lot for the video..But could not find the video no. 13 and 14. Could you please update them as well.
@Java.Brains
@Java.Brains 5 жыл бұрын
Try accessing the playlist. I've collected all the videos there in the right order for convenience.
@Java.Brains
@Java.Brains 5 жыл бұрын
kzbin.info/aero/PLqq-6Pq4lTTZSKAFG6aCDVDP86Qx4lNas
@amritraj2303
@amritraj2303 5 жыл бұрын
@@Java.Brains ..Thanks so much.. :)..Got them..
@aarongopi6749
@aarongopi6749 5 ай бұрын
can you please share this code git hub link?
@srujanb174
@srujanb174 5 жыл бұрын
can you do a post method calling stored procedure using callable statement
@johncerpa3782
@johncerpa3782 4 жыл бұрын
Great lesson!
@wiliamferraciolli5380
@wiliamferraciolli5380 4 жыл бұрын
Very interesting this topic , thank you
@manivannanpandi2364
@manivannanpandi2364 5 жыл бұрын
Sir, Could you explain in usage of difference in preferring node js frameworks Vs Spring boot framework??
@MegaMohit92
@MegaMohit92 4 жыл бұрын
I have one question here: Question: In the micro services architecture, we are internally calling other service to complete our task. So don't you think its making our application slow as compared to Monolithic application?
@arkzbh
@arkzbh 4 жыл бұрын
Yes, a single monolith doesn't have the overhead of network calls (other than making a db call or something like that which might reside in someplace else) hence should theoretically work faster and little more reliable. However, there are several other factors that can act against a monolith, for example memory use or cpu usage. Once you have a monolith, all of the application, all the threads are running on a same memory space and using the same cpus. Whereas in a distributed system, you deploy all the different microservices on different machines/vm/container, thus minimizing any potential slowness due to memory issue for starter. Also, while designing an application, you need to consider several other aspects like reusability, less downtime, scalling etc. The minimal performance benefit that a monolith may provide, most of the the gets outwaighted by the other benefits that a microservices based architecture provides.
@MegaMohit92
@MegaMohit92 4 жыл бұрын
@@arkzbh First of all thank you for the reply. Just one more question, as we know that microservices isn't suitable for all types of web application. So what are factor we should consider before developing our projects into microservices?
@arkzbh
@arkzbh 4 жыл бұрын
@@MegaMohit92 there is no straight forward answer for this one IMO. it all depends on the "need". Let's take an example, let's say I have a simple application doing some database search and returned data is displayed on ui. I'll say build a single application having html/js and java code together and deploy in tomcat as a war. But now what if I get a request from client to change the ui too frequently. Everytime I need to redeploy the whole application and any other project that may be using my api to search, that also needs to wait. In that case I'll suggest a microservices based approach, a react/angular based ui app and a separate spring boot java app. The ui app can call the java apis using api url. But if I don't have all these kind of requirements, then I'll go for monolith to avoid all the extra complexities. In a nutshell, if an application can logically be splitted into 2 or more either technical or functional module, you can "start thinking" about microservices. Whether or not it's actually needed, that depends on case by case basis. Hope that clarifies something 🙂 keep learning
@commentsonly4341
@commentsonly4341 5 жыл бұрын
I tried wrapping list in object and returning json parse exception ..
@dhayanithi2020
@dhayanithi2020 5 жыл бұрын
How to avoid hard coding of Rest URL ?
@sivaganesh4489
@sivaganesh4489 4 жыл бұрын
Alt + insert select constructor and then click on select None or use lombook and use @NoArgsConstructor
@sethuramanramaiah1132
@sethuramanramaiah1132 5 жыл бұрын
I am still not clear why should we return a newly created object instead of list. Can any one kindly brief...
@10xtenx10xtenx10xten
@10xtenx10xtenx10xten 5 жыл бұрын
I think this is what he means. In the video: [{"movieId:"1234", "rating":4}, {"movieId":"5678", "rating":3}] If we wanted to add a new attribute to the response. For example he mentions adding a full name. We'll we can't add a full name property to a list. We can add it to the Ratings object. [{"movieId:"1234", "rating":4", fullName":"John Doe"}, {"movieId":"5678", "rating":3, "fullName":"John Doe"}] But now we're repeating John Doe multiple times. If we returned an object we could put the full name property on the object instead. { "fullName":"John Doe", "ratingsList": [{"movieId:"1234", "rating":4}, {"movieId":"5678", "rating":3}] } Hopefully the formatting is ok.
@peoplethesedaysberetarded
@peoplethesedaysberetarded 5 жыл бұрын
10xtenx10xtenx10xten AWESOME. Thank you! Yeah, validation and documentation will be a PITA unless you can just say, “it’s this object.” That way, you throw your docs/JSR303/383 at that class, and you’re done.
@mehdis948
@mehdis948 2 жыл бұрын
@@10xtenx10xtenx10xten Why we cannot return a list anymore? we can have an API response like this: [{"movieId":5870,"rating":5},{"movieId":1234,"rating":3},"John Doe"] and it is its code: @GetMapping("-sth-") public List foo() { List finalList = new ArrayList(); finalList.add(new Rating(5870L, 5)); finalList.add(new Rating(1234L, 3)); finalList.add("John Doe"); return finalList; }
@10xtenx10xtenx10xten
@10xtenx10xtenx10xten 2 жыл бұрын
@@mehdis948 To be clear, there's nothing stopping you from returning your list like that. But how are you going to explain to the client where the name is? Are you going to promise that it will always be in index 2? What happens when you add another rating.
@mehdis948
@mehdis948 2 жыл бұрын
@@10xtenx10xtenx10xten I got it. thank you so much
@mucyomiller_
@mucyomiller_ 5 жыл бұрын
create empty constructor you have to click on select none on that window :)
@VictorMartinez-gn5fk
@VictorMartinez-gn5fk 3 жыл бұрын
¿Isn't that a DTO?
@siddharthslayer1562
@siddharthslayer1562 4 жыл бұрын
Thanks a lot.
@mohammedyassinhamdaoui8634
@mohammedyassinhamdaoui8634 4 жыл бұрын
Useful tip
@mihaelvinkovic3929
@mihaelvinkovic3929 5 жыл бұрын
Be a lazy programer use Lombok :D
@HabilNaqati
@HabilNaqati 2 жыл бұрын
@Setter & @Getter 😌
@mandarnaik9901
@mandarnaik9901 2 жыл бұрын
I didn't understood your explanation quit well? can someone please elaborate to me?
@cmdrshepard
@cmdrshepard 5 жыл бұрын
ALT + INS; Enter; ALT+N
@ravideviceregunta5794
@ravideviceregunta5794 4 жыл бұрын
Awesome
@aninjamnky
@aninjamnky 3 жыл бұрын
If I'm needing to purely return a list of objects, I don't really think the worry for backward compatibility really applies there. If you're returning more than that list (like the name of someone, as his example), I can see the need for a wrapper object. But, the worry about new additional fields in an object is really taken care of by Jackson's annotations, specially @JsonIgnoreProperties(ignoreUnknown = true). Any downstream processes should be ignoring unknown properties anyways. I was looking at this video to see if sending a list was a bad practice or potentially slower when deserializing, I can't say I really got my answer here lol.
@dazelmann6589
@dazelmann6589 4 жыл бұрын
Its always easy to remove code than to add some. ~Koushik 2k20
@NotNotNithin
@NotNotNithin 5 жыл бұрын
I love your tuts, but please take good care of your eyes though man. They might pop out some day🙈
@ambaragrawal9134
@ambaragrawal9134 5 жыл бұрын
Lolzzz...
@nicko274
@nicko274 5 жыл бұрын
Hey Koushik... I know how to create an empty constructor in Intelli-J! Type "public", then type, "Rating", then "()", then "{", then "}" Whaalaah!!
@mehdis948
@mehdis948 2 жыл бұрын
Why we cannot return a list anymore? we can have an API response like this: [{"movieId":5870,"rating":5},{"movieId":1234,"rating":3},"John Doe"] and it is its code: @GetMapping("-sth-") public List foo() { List finalList = new ArrayList(); finalList.add(new Rating(5870L, 5)); finalList.add(new Rating(1234L, 3)); finalList.add("John Doe"); return finalList; }
@mehdis948
@mehdis948 2 жыл бұрын
Why we cannot return a list anymore? we can have an API response like this: [{"movieId":5870,"rating":5},{"movieId":1234,"rating":3},"John Doe"] and it is its code: @GetMapping("-sth-") public List foo() { List finalList = new ArrayList(); finalList.add(new Rating(5870L, 5)); finalList.add(new Rating(1234L, 3)); finalList.add("John Doe"); return finalList; }
Гениальное изобретение из обычного стаканчика!
00:31
Лютая физика | Олимпиадная физика
Рет қаралды 4,8 МЛН
Мясо вегана? 🧐 @Whatthefshow
01:01
История одного вокалиста
Рет қаралды 7 МЛН
VIP ACCESS
00:47
Natan por Aí
Рет қаралды 30 МЛН
Spring Boot + Spring Security + JWT from scratch - Java Brains
39:29
Top 25 Microservice Interview Questions Answered - Java Brains
39:54
Microservices using SpringBoot | Full Example
1:21:39
Daily Code Buffer
Рет қаралды 1 МЛН
19 Starting a Eureka server - Spring Boot Microservices Level 1
9:00