0

I have JSON data which looks like this and I stored this data in ArrayList using a POJO class.

[
    {
        "date": "2019-10-30",
        "sites": [
            {
                "site_id": 1,
                "site_name": "Kanishka HO",
                "customer_id": 22,
                "customer_name": "Mahindra",
                "site_address": "202, 2nd Floor, The Crescent Business Park, Sakinaka Tele Exchange Lane,Sakinaka, Mumbai, Maharashtra-400072.",
                "site_landmark": "MTNL Telephone Exchange",
                "site_zipcode": "400062",
                "site_city": "Mumbai",
                "site_state": "Mahrashtra",
                "site_zone": "Mumbai",
                "site_latitude": "19.0998303",
                "site_longitude": "72.878795",
                "tests": [
                    {
                        "test_id": 30,
                        "test_category_id": 1,
                        "test_name": "Water Potability",
                        "collection_date": "2019-10-30 00:00:00",
                        "collection_value": 1,
                        "sample_quantity_per_test": "1.5 Ltr",
                        "sample_details_required_keys": [
                            "source_of_sample",
                            "location",
                            "description"
                        ],
                        "site_id": 1,
                        "containers": [
                            "1ltr Big Bottle * 1",
                            "500 ml Small bottle * 1",
                            "test_container_1 * 1"
                        ]
                    }
                ]
            }
        ]
    }
]

And My POJO class looks like this [POJO]

public class ScheduleResponse implements Serializable {

    private static final int DATE_TYPE = 1;
    private static final int ITEM_TYPE = 2;
    private String date;
    private Sites[] sites;
    public int viewType;

    public ScheduleResponse(String date, Sites[] sites, int viewType) {
        this.date = date;
        this.sites = sites;
        this.viewType = viewType;
    }

    public int getViewType() {
        return viewType;
    }

    public void setViewType(int viewType) {
        this.viewType = viewType;
    }

    public String getDate() {
        return date;
    }

    public void setDate(String date) {
        this.date = date;
    }

    public Sites[] getSites() {
        return sites;
    }

    public void setSites(Sites[] sites) {
        this.sites = sites;
    }
}

POJO class for getting Sites is:

public class Sites implements Serializable {
    private String site_name;
    private String site_latitude;
    private Tests[] tests;
    private String site_address;
    private String site_id;
    private String customer_name;
    private String site_zipcode;
    private String site_landmark;
    private String site_city;
    private String site_state;
    private String site_zone;
    private String site_longitude;
    private int viewType;
    public static final int DATE_TYPE = 1;
    public static final int ITEM_TYPE = 2;


    public String getCustomer_name() {
        return customer_name;
    }

    public void setCustomer_name(String customer_name) {
        this.customer_name = customer_name;
    }

    public int getViewType() {
        return viewType;
    }

    public void setViewType(int viewType) {
        this.viewType = viewType;
    }

    public String getSite_name() {
        return site_name;
    }

    public void setSite_name(String site_name) {
        this.site_name = site_name;
    }

    public String getSite_latitude() {
        return site_latitude;
    }

    public void setSite_latitude(String site_latitude) {
        this.site_latitude = site_latitude;
    }

    public Tests[] getTests() {
        return tests;
    }

    public void setTests(Tests[] tests) {
        this.tests = tests;
    }

    public String getSite_address() {
        return site_address;
    }

    public void setSite_address(String site_address) {
        this.site_address = site_address;
    }

    public String getSite_id() {
        return site_id;
    }

    public void setSite_id(String site_id) {
        this.site_id = site_id;
    }

    public String getSite_zipcode() {
        return site_zipcode;
    }

    public void setSite_zipcode(String site_zipcode) {
        this.site_zipcode = site_zipcode;
    }

    public String getSite_landmark() {
        return site_landmark;
    }

    public void setSite_landmark(String site_landmark) {
        this.site_landmark = site_landmark;
    }

    public String getSite_city() {
        return site_city;
    }

    public void setSite_city(String site_city) {
        this.site_city = site_city;
    }

    public String getSite_state() {
        return site_state;
    }

    public void setSite_state(String site_state) {
        this.site_state = site_state;
    }

    public String getSite_zone() {
        return site_zone;
    }

    public void setSite_zone(String site_zone) {
        this.site_zone = site_zone;
    }

    public String getSite_longitude() {
        return site_longitude;
    }

    public void setSite_longitude(String site_longitude) {
        this.site_longitude = site_longitude;
    }
}

And the Tests POJO class is :

public class Tests implements Serializable {
    private String test_category_id;
    private String collection_date;
    private String site_id;
    private String[] sample_details_required_keys;
    private String[] containers;
    private String customer_name;
    private String collection_value;
    private String test_name;
    private String test_id;
    private String sample_quantity_per_test;

    public String getTest_category_id() {
        return test_category_id;
    }

    public void setTest_category_id(String test_category_id) {
        this.test_category_id = test_category_id;
    }

    public String getCollection_date() {
        return collection_date;
    }

    public void setCollection_date(String collection_date) {
        this.collection_date = collection_date;
    }

    public String getSite_id() {
        return site_id;
    }

    public void setSite_id(String site_id) {
        this.site_id = site_id;
    }

    public String[] getSample_details_required_keys() {
        return sample_details_required_keys;
    }

    public void setSample_details_required_keys(String[] sample_details_required_keys) {
        this.sample_details_required_keys = sample_details_required_keys;
    }

    public String[] getContainers() {
        return containers;
    }

    public void setContainers(String[] containers) {
        this.containers = containers;
    }

    public String getCustomer_name() {
        return customer_name;
    }

    public void setCustomer_name(String customer_name) {
        this.customer_name = customer_name;
    }

    public String getCollection_value() {
        return collection_value;
    }

    public void setCollection_value(String collection_value) {
        this.collection_value = collection_value;
    }

    public String getTest_name() {
        return test_name;
    }

    public void setTest_name(String test_name) {
        this.test_name = test_name;
    }

    public String getTest_id() {
        return test_id;
    }

    public void setTest_id(String test_id) {
        this.test_id = test_id;
    }

    public String getSample_quantity_per_test() {
        return sample_quantity_per_test;
    }

    public void setSample_quantity_per_test(String sample_quantity_per_test) {
        this.sample_quantity_per_test = sample_quantity_per_test;
    }
}

I want to convert this ArrayList as a string and store it somewhere and when needed want to retrieve the same JSON data with the same format. Is there any possible way? TIA.

16
  • Yes, store it as a String. Is it not a String already? If not what is it? Commented Oct 30, 2019 at 8:27
  • It's an ArrayList of a type POJO class or model class @ScaryWombat Commented Oct 30, 2019 at 8:29
  • Huh? What do you mean? Commented Oct 30, 2019 at 8:30
  • I edited my question hope you understand now @ScaryWombat Commented Oct 30, 2019 at 8:36
  • 1
    no problem, whenever you ask a question, please make sure to include everything related to your question here, on stack overflow. even now, please edit your question to include the code you have in your actual question, don't point to a link Commented Oct 30, 2019 at 9:02

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.