Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to send an hashmap with the Postman Chrome extension?

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;
}
like image 239
Kiran Avatar asked Apr 19 '16 04:04

Kiran


3 Answers

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.

like image 76
Hassingard Avatar answered Oct 26 '22 22:10

Hassingard


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"
}
like image 25
asg Avatar answered Oct 26 '22 23:10

asg


You can pass a map with postman like this,

attribute: {
    "key": "value",
    "key2": "value2"
}
like image 43
Galahad Avatar answered Oct 27 '22 00:10

Galahad