0

I'm scraping a web api with this Java code:

import kong.unirest.HttpResponse;
import kong.unirest.Unirest;
import kong.unirest.json.JSONObject;

public class Scr {
    public static void main(String[] args) {
        Unirest.config().enableCookieManagement(false);
        HttpResponse<String> response = Unirest.post("https://www.cse.lk/api/financials")
                .header("content-type", "application/x-www-form-urlencoded; charset=UTF-8")
                .body("symbol=DIPD.N0000")
                .asString();

        JSONObject json = new JSONObject(response.getBody());
        //System.out.println(json.toString(4));
    }
}

which throws a json that looks like this: https://pastebin.com/ZqqB5H8C

What I want to figure out is how to deserialize the json into a java object. This is the encapsulated bean I wrote to deserialize the json.

public class ComData {
    private List<FileData> infoAnnualData = new ArrayList<FileData>();
    private List<FileData> infoQuarterlyData = new ArrayList<FileData>();
    private List<FileData> infoOtherData = new ArrayList<FileData>();
    private List<InfoWebLink> infoWebLink = new ArrayList<InfoWebLink>();
    private List<ReqFinancial> reqFinancial = new ArrayList<ReqFinancial>();
    private InfoCompanyBannerAd infoCompanyBannerAd;
// getters and setters goes here
}
  • 2
    there are examples [here](https://stackoverflow.com/questions/20534862/how-to-efficiently-map-a-org-json-jsonobject-to-a-pojo) – MaxG Oct 01 '21 at 00:17
  • This tutorial was quite helpful for this problem. Posting it here for reference if anyone's interested https://json2csharp.com/json-to-pojo – Sathimantha Malalasekera Oct 01 '21 at 21:02

0 Answers0