I have seen number of matching questions but non answered my problem. I want to make following code snippet dynamic in a way that I am not sure that my API will return a single object or an array of objects.
List<Article> article = null;
I have seen different examples like below, but this does not answer my question:
List<Animal> animals = new ArrayList<>();
The thing is, I have article variable defined in my Java gson model class, and I really have no idea how can I handle a response and make my article to behave dynamically. So, if there is a single object then it should act like single object instead of List, and if there is array of objects then it should act like List.
I am also not sure if something like this will work or not but I am looking for following type of functionality in any do able form:
<T> Article article = null;
Note: I have also seen this Generic Type Doc. but this doesn't help to solve my problem.
Consider extending the ArrayList with methods that internally perform aggregation methods so that externally it behaves the same whether there is 0, 1, or N number of internal objects.