Type safety: Unchecked cast from PortfolioManagerApplication.Stocks to List<String>

My build is failing because of this error. I’m casting trades to a list since the return type of mainReadFile is list. But i get this error. How do i get around this?

You need to return only the symbols in this method, not the whole stock. Try doing it that way.

Let me know if it helps!

Yea Ik. In my Stocks class, I’ve put only symbol. So the output would be just symbols for now. The problem is with type casting. Objectmapper outputs of type PortfolioManagerApplication.Stocks but the mainReadFile function returns of type List. Thus I’m facing a contradiction there even when I type cast the output of object mapper to a list.

Use a simple loop to iterate through all Stocks objects and add their symbols to a List object which you can return.

Understood. thanks for helping out

No problem. Mark it as solution if it works.