So it turns out I was working (I'm not a Senior Developer yet as you can see) while out of the blue I realized something was wrong with my code. A Hashmap receives "true" instead of receiving an ArrayList with one object in its first position. As a matter of example you can see what I'm talking about as follows:
Product item = new Product();
Map rMap = new HashMap();
rMap.put("productsList", new ArrayList().add(item));
After certain lines of code, and coding helperMethods I attempted to retrieve that "productsList" from the map but I couldn't do so, I didn't know why so after debugging it I found out that when the PUT was done, there was no such a list, just a Boolean value. The way I retrieved it was as follows:
if (rMap.containsKey("productsList")) {
// This IF statement was being skipped because of the Boolean
if (rMap.get("productsList") instanceof ArrayList) {
List<Product> pr = (List) rMap.get("productsList");
}
}
On the other hand I've got this (which is way more clear) and woks as expected:
Product item = new Product();
Map rMap = new HashMap();
List < Product > myList = new ArrayList();
myList.add(item);
rMap.put("productsList", myList);
What could be done in order to reduce those two lines of code where a List is created and a Object is set to the list? It's not a big deal of course, it's just I want to make my coding clearer and staightforward.