2

I have to deal with an API with many nested dynamic JSON keys with a lot of nesting.

My Json Response is like that:

{
"success": true,
"data": {
    "infoArr": {
        "868.111": {
            "COURSE_ID": "868.111",
            "COURSE_NAME_PL": "DRILLING EQUIPMENT DESIGN",
            "COURSE_NAME_SL": "تصميم معدات حفر",
            "COURSE_NAME": "DRILLING EQUIPMENT DESIGN",
            "COURSE_CODE": "PE4206",
            "COURSE_CREDITS": "3",
            "REG_CREDITS_COUNT": "3",
            "REQUIREMENT_TYPE_ID": "5",
            "REQUIREMENT_ID": "26.111",
            "REQUIREMENT_TYPE_PL": "Mandatory Degree Requirements",
            "REQUIREMENT_TYPE_SL": "متطلبات الشهادة الإجبارية",
            "REQUIREMENT_TYPE": "Mandatory Degree Requirements",
            "CREDITS_COUNT": "162",
            "REQUIREMENT_PASSED_CREDITS": "127",
            "IS_REQUESTABLE": "Y",
            "STATUS_REASON_PL": "Passed All Conditions",
            "STATUS_REASON_SL": "يمكن تسجيل المقرر",
            "STATUS_REASON": "Passed All Conditions",
            "YEAR_ORDER": "4",
            "SEMESTER_ORDER": "1",
            "PASSED_PREREQUISITES": ",",
            "LAST_REGISTER_SEMESTER_ID": "20171",
            "REGISTER_STATUS": "R",
            "FINISH_STATUS": "F",
            "SUB_TOTAL": "26.5",
            "FINAL_EXAM": "21",
            "FINAL_MARK": "48",
            "LAST_REGISTER_SEMESTER_PL": "First Semester 2017/2018",
            "LAST_REGISTER_SEMESTER_SL": "الفصل الأول  2017/2018",
            "SERIAL": 1
        },
        "871.111": {
            "COURSE_ID": "871.111",
            "COURSE_NAME_PL": "SECONDARY RECOVERY",
            "COURSE_NAME_SL": "الاستخلاص المعزز",
            "COURSE_NAME": "SECONDARY RECOVERY",
            "COURSE_CODE": "PE4209",
            "COURSE_CREDITS": "3",
            "REG_CREDITS_COUNT": "3",
            "REQUIREMENT_TYPE_ID": "5",
            "REQUIREMENT_ID": "26.111",
            "REQUIREMENT_TYPE_PL": "Mandatory Degree Requirements",
            "REQUIREMENT_TYPE_SL": "متطلبات الشهادة الإجبارية",
            "REQUIREMENT_TYPE": "Mandatory Degree Requirements",
            "CREDITS_COUNT": "162",
            "REQUIREMENT_PASSED_CREDITS": "127",
            "IS_REQUESTABLE": "Y",
            "STATUS_REASON_PL": "Passed All Conditions",
            "STATUS_REASON_SL": "يمكن تسجيل المقرر",
            "STATUS_REASON": "Passed All Conditions",
            "YEAR_ORDER": "4",
            "SEMESTER_ORDER": "2",
            "PASSED_PREREQUISITES": ",",
            "LAST_REGISTER_SEMESTER_ID": "20164",
            "REGISTER_STATUS": "E",
            "FINISH_STATUS": "F",
            "SUB_TOTAL": "17",
            "FINAL_EXAM": "12",
            "FINAL_MARK": "29",
            "LAST_REGISTER_SEMESTER_PL": "Complementary Period 2016/2017",
            "LAST_REGISTER_SEMESTER_SL": "الدورة التكميلية  2016/2017",
            "SERIAL": 1
        }
    },
    "requestCourseArr": {
        "868.111": {
            "COURSE_ID": "868.111",
            "COURSE_NAME_PL": "DRILLING EQUIPMENT DESIGN",
            "COURSE_NAME_SL": "تصميم معدات حفر",
            "COURSE_NAME": "DRILLING EQUIPMENT DESIGN",
            "COURSE_CODE": "PE4206",
            "COURSE_CREDITS": "3",
            "REG_CREDITS_COUNT": "3",
            "REQUIREMENT_TYPE_ID": "5",
            "REQUIREMENT_ID": "26.111",
            "REQUIREMENT_TYPE_PL": "Mandatory Degree Requirements",
            "REQUIREMENT_TYPE_SL": "متطلبات الشهادة الإجبارية",
            "REQUIREMENT_TYPE": "Mandatory Degree Requirements",
            "CREDITS_COUNT": "162",
            "REQUIREMENT_PASSED_CREDITS": "127",
            "IS_REQUESTABLE": "Y",
            "STATUS_REASON_PL": "Passed All Conditions",
            "STATUS_REASON_SL": "يمكن تسجيل المقرر",
            "STATUS_REASON": "Passed All Conditions",
            "YEAR_ORDER": "4",
            "SEMESTER_ORDER": "1",
            "PASSED_PREREQUISITES": ",",json
            "LAST_REGISTER_SEMESTER_ID": "20171",
            "REGISTER_STATUS": "R",
            "FINISH_STATUS": "F",
            "SUB_TOTAL": "26.5",
            "FINAL_EXAM": "21",
            "FINAL_MARK": "48",
            "LAST_REGISTER_SEMESTER_PL": "First Semester 2017/2018",
            "LAST_REGISTER_SEMESTER_SL": "الفصل الأول  2017/2018",
            "SERIAL": 1
        },
        "871.111": {
            "COURSE_ID": "871.111",
            "COURSE_NAME_PL": "SECONDARY RECOVERY",
            "COURSE_NAME_SL": "الاستخلاص المعزز",
            "COURSE_NAME": "SECONDARY RECOVERY",
            "COURSE_CODE": "PE4209",
            "COURSE_CREDITS": "3",
            "REG_CREDITS_COUNT": "3",
            "REQUIREMENT_TYPE_ID": "5",
            "REQUIREMENT_ID": "26.111",
            "REQUIREMENT_TYPE_PL": "Mandatory Degree Requirements",
            "REQUIREMENT_TYPE_SL": "متطلبات الشهادة الإجبارية",
            "REQUIREMENT_TYPE": "Mandatory Degree Requirements",
            "CREDITS_COUNT": "162",
            "REQUIREMENT_PASSED_CREDITS": "127",
            "IS_REQUESTABLE": "Y",
            "STATUS_REASON_PL": "Passed All Conditions",
            "STATUS_REASON_SL": "يمكن تسجيل المقرر",
            "STATUS_REASON": "Passed All Conditions",
            "YEAR_ORDER": "4",
            "SEMESTER_ORDER": "2",
            "PASSED_PREREQUISITES": ",",
            "LAST_REGISTER_SEMESTER_ID": "20164",
            "REGISTER_STATUS": "E",
            "FINISH_STATUS": "F",
            "SUB_TOTAL": "17",
            "FINAL_EXAM": "12",
            "FINAL_MARK": "29",
            "LAST_REGISTER_SEMESTER_PL": "Complementary Period 2016/2017",
            "LAST_REGISTER_SEMESTER_SL": "الدورة التكميلية  2016/2017",
            "SERIAL": 1
        }
    },
    "groupCourseArr": {
        "868.111": {
            "T_GROUPS": {
                "30669": "1 (0/40)",
                "": ""
            },
            "P_GROUPS": {
                "30670": "1 (0/20)",
                "30671": "2 (0/20)",
                "": ""
            },
            "T_GROUPS_OPTIONS": [],
            "P_GROUPS_OPTIONS": []
        },
        "871.111": {
            "T_GROUPS": {
                "30672": "1 (0/40)",
                "": ""
            },
            "P_GROUPS": {
                "": ""
            },
            "T_GROUPS_OPTIONS": [],
            "P_GROUPS_OPTIONS": []
        }
    }
  }
}

My question is how to deal with this data type since it doesn't have a const SerializedName to serialize it using Gson and generate an appropriate POJO Class for that response.

I'm using Retrofit to handle the network operations.

Edit: I look for an easier way to do that other than iterate through a series of JsonObjects and Maps of Entry since there are more complicated and nested API requests in the server.

Community
  • 1
  • 1
Ali Habbash
  • 777
  • 2
  • 6
  • 29
  • 2
    Possible duplicate of [How to parse a dynamic JSON key in a Nested JSON result?](https://stackoverflow.com/questions/7304002/how-to-parse-a-dynamic-json-key-in-a-nested-json-result) – Mohamed Mohaideen AH Oct 28 '18 at 13:35

0 Answers0