Skip to content
Advertisement

why MultiMap.add() is producing like {Test_Case: [[1.0, 2.0, 3.0]]} but it should be {Test_Case: [1.0, 2.0, 3.0]}

This is the piece of code where key is of type String and value is List, but when i collecting all list elements and adding same to MultiMap object its adding as [[]], The intension of using MultiMap is due to im having same key with different values (here “$.name” is having multiple values)

            List<String> header = funGetSheetColumns(wb, sSheetName);
            List valueList;
            MultiMap resMap = new MultiMap();

            for (int j = 0; j < header.size(); j++) {
                valueList = new ArrayList();
                for (List data : tableRS) {

                    valueList.add(data.get(j));
                }

                resMap.add(header.get(j), valueList);
            }

this is the output im getting

$.name: [[a, b, c], [a1, b1, c1], [a2, b2, c2]]
RequestBody: [[{
  "id": 0,
  "category": {
    "id": 0,
    "name": "string"
  },
  "name": "doggie",
  "photoUrls": [
    "string"
  ],
  "tags": [
    {
      "id": 0,
      "name": "string"
    }
  ],
  "status": "available"
}, {
  "id": 0,
  "category": {
    "id": 0,
    "name": "string"
  },
  "name": "doggie",
  "photoUrls": [
    "string"
  ],
  "tags": [
    {
      "id": 0,
      "name": "string"
    }
  ],
  "status": "available"
}, {
  "id": 0,
  "category": {
    "id": 0,
    "name": "string"
  },
  "name": "doggie",
  "photoUrls": [
    "string"
  ],
  "tags": [
    {
      "id": 0,
      "name": "string"
    }
  ],
  "status": "available"
}]]
}

but it shouldn’t be inside array of array[[]]

please let me know what im missing.

Advertisement

Answer

I think you need something like the following ( untested ) code. I’ve never used MultiMap, but it looks like you just add items to it like it was a normal map, and it takes care of adding them to a collection mapped to the key.

        List<String> header = funGetSheetColumns(wb, sSheetName);
        MultiMap resMap = new MultiMap();

        for (int j = 0; j < header.size(); j++) {
            for (List data : tableRS) {
                resMap.add(header.get(j),data.get(j));
            }

        }

That’s what this link seems to indicate anyway.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement