0 votes
in Programming by (2.4k points)
public class RestfulControllerImpl implements RestfulController {

  @Override
  @RequestMapping(value = "maptest", method = RequestMethod.GET)
  @ResponseBody
  public Object mapReturn() {
    HashMap<String, String> map = new HashMap<String, String>();
    map.put("name", "test1");
    map.put("sex", "male");
    map.put("address", "1324");
    map.put("old", "123");
    return map;
  }  
}

I want to return a map<string, string> for the request, and it occurs

HTTP-406 not acceptable

How to implement the method to return a response body with a map and it shows in like a json object?

1 Answer

0 votes
by (1.9k points)

Return map instead of object.

 @RequestMapping(value = "maptest", method = RequestMethod.GET)
        @ResponseBody
        public Map<String,String> mapReturn() {
            HashMap<String, String> map = new HashMap<String, String>();
            map.put("name", "test1");
            map.put("sex", "male");
            map.put("address", "1324");
            map.put("old", "123");
            return map;
        } 

Here is your answer have a look!

...