Can't Read Json file

I tried various ways but cant overcome the error. I cant read the json file in cmd. I got the following error.

unreported exception IOException; must be caught or declared to be thrown
PortfolioTrade [] trade = objectMapper.readValue(new File(path to json_file), PortfolioTrade[].class);

Please help, @gouravsardana, @amanagar, @Vinod_Crio_TA.

Hi @Soumyadip,

IOException can be caused if the resource we have asked to read in isn’t present or can’t be accessed. The error asks to either catch the IOException (using try-catch statements) or the class method including this code should throw the required exception

Hope it helps :slight_smile:

1 Like

There are different functions provided in main java file.
Try not to hardcode path.
And use one the functions and then use the output of that function as argument for readvalue

Your error is telling everything what needs to be done just see Exception handling techniques in java read about it.

1 Like

If I have to make changes in code in getObjectMapper() or other functions to read the json file ?

Not able to understand your question?