Way of searching
Do you experience these moments? While writing code, you come across a really strange problem, so you spend about ten hours looking for information, but you come up empty-handed.
I do. Last two weeks I faced a question which is that I created a POST API and transffered a request body to a entity I created as an input. But the controller cannot turned any field in the request into the field in the entity, which means, I have an instance of this entity with all null value. So I searched this problem for about 10 hours in total, but I did get nothing which made me go mad. I also asked my friend in the University and colleagues to help me debugging, but they were still confused because there seems no problem in my code and http request. When we just wanted to give up, I thought maybe I could ask my boyfriend since he was my older schoolmate. After about 30 minutes, he gave me three links, which solved my problem immediately. Everytime he faces some problem, he can find his resource in a really fast way. Therefore, I asked him about his tricks on searching.
- First, it is important to figure out exactly which part of the problem is most directly related to. Initially, the problem is not a case of generating an entity with all null values, but rather a NullPointerException, and it’s on the service class. So I used a power-down test to find the source of the problem. If I had just looked up the solution to the NullPointerException, I probably wouldn’t have gotten an answer right away that was more in line with my underlying problem.
- Second, when we find the most fundamental problem, try to describe the problem in the simplest and most direct way possible. In my own query, I have been using “the request body cannot be resolved to an entity” + “POST API” + “Sprigboot” as the keywords. The result is that I get very few answers, and it seems like the answers are more focused on the direction of resolve because there are too many keywords. When my boyfriend was querying, he didn’t include the POST API keyword because he decided that the problem might not have much to do with the POST API. The keywords he searched for were DTO+springboot+RequestBody+field+all+null, using a lot of words rather than full words to describe the problem. I’m guessing he’s making it better understood by the search engines this way and thus finding the answer faster.
- Finally, he points out how we can’t give up lightly when searching for answers. Persistence, and then switching multiple directions, is the key to successful problem solving.
Thanks again to my boyfriend Michael Mai for giving me a great inspiration on programming. I also hope that his method has improved the speed and accuracy of finding questions for those of you who are reading.