Search code examples
jsonkotlinmappingparcelable

How do I map a JSON object with generic names in a list?


So I've got this JSON format coming my server(names and values have been changed)

{
"Test.Tester": {
    "test1": "value",
    "test2": "value",
    "test3": 1,
    "test4": 1000,
    "test5": true,
    "test6": [],
    "test7": {
        "RAW,1": [
            [
                "287220",
                "287220",
                "287220",
                "287220",
                "287220",
                "287220",
                "287220"
            ],
            [
                "180",
                "180",
                "180",
                "180",
                "180",
                "180",
                "180"
            ],
            [
                "105",
                "105",
                "105",
                "105",
                "105",
                "105",
                "105"
            ],
            [
                "290220",
                "290220",
                "290220",
                "290220",
                "290220",
                "290220",
                "290220"
            ],
            [
                "190",
                "190",
                "190",
                "190",
                "190",
                "190",
                "190"
            ]
        ],
        "RAW,2": [
            [
                "473460",
                "473460",
                "473460",
                "473460",
                "473460",
                "473460",
                "473460"
            ],
            [
                "474460",
                "474460",
                "474460",
                "474460",
                "474460",
                "474460",
                "474460"
            ],
            [
                "475460",
                "475460",
                "475460",
                "475460",
                "475460",
                "475460",
                "475460"
            ],
            [
                "476460",
                "476460",
                "476460",
                "476460",
                "476460",
                "476460",
                "476460"
            ],
            [
                "477460",
                "477460",
                "477460",
                "477460",
                "477460",
                "477460",
                "477460"
            ]
        ]
    },
    "httpStatusCode": 200,
    "httpStatusReason": "OK"
}

First off, I really don't like this format they send it in, but they can't change it. So I have to wrap stuff in the first "Test.Tester" object. And I use data classes and Parcelable/Parcelize.

An example of my object could be this:

@Parcelize
data class TestRequestDTO(@SerializedName("Test.Tester") val 
test: TestDTO) : Parcelable

@Parcelize
data class TestDTO(
    val test1: String,
    val test2: String,
    val test3: Int
) : Parcelable

I'm having a hard time figuring out how I can map this test7. It's an object, with a list of String arrays, called RAW,X. The X can be any amount as far as I'm told. Can anyone think of a clever way to do this?


Solution

  • Simply solves it by saying

    val values : Map<String, List<List<Float>>>