0

I am working on a Spring-MVC application in which for this single method I am getting an error as Unsupported media type. None of the other methods have this problem. Any help would be nice. Thank you-.

Java Code :

@RequestMapping(value = "/setnotificationlevels")
    public
    @ResponseBody
    boolean setNotificationLevels(@RequestParam("groupid") long groupid, @RequestBody GroupMembers member) {
        System.out.println("Set notification levels is called. ");
        return this.groupMembersService.setNotificationLevels(member, groupid);
    }

JS code :

setEmailNotifications : function (groupid, settings){
            return $.ajax({
                url: "/setnotificationlevels?groupid=" + groupid,
                type: 'POST',
                cache:false,
                data : JSON.stringify(settings),
                contentType: "application/json; charset=utf-8"
            });
        },

Error log :

description The server refused this request because the request entity is in a format not supported by the requested resource for the requested method.

Thank you.

We are Borg
  • 5,117
  • 17
  • 102
  • 225
  • Is your `member` parameter correctly set? See also [this question](http://stackoverflow.com/questions/19468572/spring-mvc-why-not-able-to-use-requestbody-and-requestparam-together) – barbsan May 10 '17 at 11:26
  • @barbsan : What do you mean by that? – We are Borg May 10 '17 at 11:37
  • I mean that 4th example from this link is similar to your case. Accepted answer there explains that data in `@RequestBody` is lost when you have both `@RequestBody` and `@RequestParam` specified. – barbsan May 10 '17 at 12:15

2 Answers2

1

tell your java code that its a post or get http methd:

@RequestMapping(value = url, method = RequestMethod.POST) public@ResponseBody StringOrAnyResponseObject fName(@RequestBody final Object o) {}

and in your js: in any function return $http.post(url,parameterMap);

-1

Try to add consumes = "application/json;charset=UTF-8" to @RequestMapping annotation.

Kamil
  • 2,712
  • 32
  • 39