I want to send a HashMap object to a ReST resource as a POST variable. I used the Form class to send the object. The client code:
public static
send Map as POST request body
@POST
@Produces("application/json")
@Consumes("application/json")
@Path("/sendUser")
public Response sendUser(Map usersMap) {
String name = usersMap.get("Name");
// first check for existing key
String family = usersMap.get("Family");
String phone = usersMap.get("Phone");
String mobile = usersMap.get("Mobile");
return Response.ok("Get user attributes successfully !").build();
}
get map response from POST
@POST
@Produces("application/json")
@Consumes("application/json")
@Path("/getUser")
public Response getUser(String searchInputJsonString) {
Map usersMap = new HashMap<>();
usersMap.put("Name","Johm");
usersMap.put("Family","W.R.Klein");
usersMap.put("Phone","87540255");
usersMap.put("Mobile", "112458033");
return Response.ok(usersMap).build();
}