5
votes

I've been using Postman Chrome extension to test out my API and would like to send an Hashmap via post. Is there a way to send something map as a parameter in Postman?

 HashMap inputHM = new HashMap();

                        inputHM.put("MVMT", "VL");
                        inputHM.put("NO", 1);
                        inputHM.put("FE", "E");
                        inputHM.put("CT", "20");
                        inputHM.put("HT", "80");
                        inputHM.put("TYPE", "GP");
                        inputHM.put("OPR_CD", "MAEU");
                        inputHM.put("LOCATION", "BERT");
                        inputHM.put("TMNL", "1");
                        inputHM.put("INCL", "");
                        inputHM.put("ID", 1);

My Controller is as follows

@RequestMapping(value = "/getBest", method = RequestMethod.POST)
public @ResponseBody
JsonResponse getBest(@RequestBody HashMap hm) {

    JsonResponse json = new JsonResponse();
    json.setSuccessData(rdtRequestService.getBest(hm));
    return json;
}
3
You'll need to create json array and send it to the serverApurva

3 Answers

4
votes

When you send the request through POSTMAN, select the type as POST, then select the "raw" option and then just send JSON in the "body" with the values you want to put in your HashMap. Remember to select "application/json". Jackson will transform the JSON into a HashMap for you.

An example fragment from your code would be:

{
 "NO": 1,
 "FE": "E",
 "CT": "20"
}

Jackson will do the rest for you, I mean, mapping that JSON to your HashMap.

3
votes

Please use the following payload in the POSTMAN for a POST method. Please take a look at this post.

{
    "LOCATION": "BERT",
    "TMNL": "1",
    "NO": 1,
    "CT": "20",
    "OPR_CD": "MAEU",
    "MVMT": "VL",
    "ID": 1,
    "HT": "80",
    "INCL": "",
    "TYPE": "GP",
    "FE": "E"
}
1
votes

You can pass a map with postman like this,

attribute: {
    "key": "value",
    "key2": "value2"
}