Could not Understand Faq right..!

I could not understand given code in faq.

ObjectMapper mapper = new ObjectMapper();
RestTemplate restTemplate = new RestTemplate();
String result = restTemplate.getForObject(url, String.class);
List collection = mapper.readValue(result,
new TypeReference<ArrayList>() {
});

We will get each unique result string for every URL that includes the name of a stock.
String result will look like a dictionary in appearance and when It will be passed in readValue function a POJO class should be returned why is there List of POJO class?

I don’t understand this Can someone help me ?

You dont need to implement the FAQ in the same way it is shown. It is just an example.
You can do different things such as storing the api response as an array of pojo class (you already did this in module 1)

The dictionary contains multiple lists. To map every list to a POCO class, a list of POCO class is used.

I think you should say returning response contains list of multiple dictionaries but
But if I pass name of stock in url then response list will contain one dictionary then why do I need list of poco class.
we will need list of poco class if we somehow make and url without specifying name of perticular stock but here we have to make url call for every stock name hence returning one dictionary per list in responce.

So I want to do it like this
TiingoCandle t1 = restTemplate.getForObject(url, TiingoCandle.class)

but in debugging I was never able to put a breakpoint after this line and in doing so debugger never pauses and I am not able to debug not even this line that what is happening in this line?

remember the result is an array. can’t say more.

Lets address you querry like this, If you will look at the trades.json file there are multiple stocks namely aapl, msft, googl. Just think of it what you are doing here, you are passing the json file which has to be mapped to your portfolioManagerApplication.java, TiingoCandle t1 = restTemplate.getForObject(url, TiingoCandle.class)
this will give you one object of tiingoCandle mapped with the output of the response from api, and the above command should very well work if the reponse of the api was limited to 1 but what if the response of api is bigger that is there are multiple dictionaries , how do you plan to solve this in that case. Try running the api in your command line using curl, see its output and you will be able to answer your question yourself.

My bad, the list contains multiple dicts.
https://api.tiingo.com/documentation/end-of-day
Check this link for sample response (Examples). Maybe you will get a clear idea.

what I am doing:
loop for the size number of stock in trades.json
{
different url for every stock that is in trades.json;
creating an object t1 for that URL that is specific for a stock;
adding an entry in a Treemap for t1.getClose() for that stock and name of stock;
}
because treeMap is always sorted according to its values;
taking the name of stocks in a new array list;
returning that list;

I am not able to understand how we can make an generalize url that will work for multiple stocks so that we could get array of strings.

maybe this will help

@nabhanpv Please Help !
I understood that point but now I wanna understand
List collection = mapper.readValue(result,new TypeReference<ArrayList>() {});

what is the variable collection?

You have provided as arguments to the readValue() method,

  1. result - which would be the file object for the resource from which you have to read the JSON data
  2. new TypeReference<ArrayList>() - which asks the readValue() method to store contents of the JSON file as an ArrayList of instances of the type TypeReference

Now, the mapper.readValue() method returns an ArrayList of TypeReference objects - just what we asked for. And, collection is the variable which stores the reference to the ArrayList

Hope it helps

Okay I got it what you well explained but I am not able to loop through collection.
I am failing in collection[i] or collection.get(i) …!
How will I be able to extract field from this ArrayList?
If I am not wrong We have to create loop inside loop. first for trades.json symboles and inside it extracting fields from collection ArrayList unique for every stock symbole. Am I on the right track ?

For Module 2,
I think we have to

  1. Call the Tiingo API for each of the stock in trades.json to get the closing price on the given end date
  2. Return a list of stock symbols sorted by their closing price

For easy sorting of an object, you can extend the corresponding class with comparator or comparable

Yes I have already read objectives

What error are you getting when using collection.get(i)?

@Kunal @AmoghaKS
I am getting this error on the mapping of stock name and the closing price on endDate by (HashMap or TreeMap both).
This error when running test case { of filename and endDate }for mainReadQuote

I also tried this but whole program never terminates may be an infinite loop.
List< TiingoCandle > collection = mapper.readValue(result,new TypeReference <List < TiingoCandle > >(){});

Have you defined the type of list, because this should work perfectly fine
List collection = mapper.readValue(result,new TypeReference(){});
but you have add necessary details in this

@sashi_Crio.Do @Saurav_Crio.Do @Rahul-Crio.do It’s been whole week since I’m on module 2.pease help me!

I have also tried this.
List< TiingoCandle > collection = mapper.readValue(result,new TypeReference<ArrayList < TiingoCandle > >(){});