I am trying to make a POST call using fiddler to a spring rest API,
@RequestMapping(value = "/GetPlanByBasicContext/", method = RequestMethod.POST)
public @ResponseBody TravelPlan getPlanByBasicContext(@RequestBody BasicPlanContext b) {
return planService.getPlan(b));
}
Request on fiddler:
http://localhost:8080/now/travelPlan/GetPlanByBasicContext/
Header:
User-Agent: Fiddler
Host: localhost:8080
Content-Length: 248
POST payload:
{
"sourceLocation": "",
"destinationLocation": "",
"modeOfTransport": "car",
"travellers": {
"age1to16": 0,
"age17to30": 0,
"age31to50": 0,
"age50plus": 0
},
"dates": {
"startDate": "",
"endDate": ""
}
}
The attributes in payload are same as that in class BasicPlanContext, along with getter and setter.
I get following error:
415 Unsupported Media Type
The server refused this request because the request entity is in a format not supported
by the requested resource for the requested method.
Tried replacing @RequestBody with @ModelAttribute, which didnt help.
Also I have following libs:
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.4.3</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.4.3</version>
</dependency>
EDIT 1: Tried adding following to the header,
Content-Type: application/json
And following to the POST method,
@RequestMapping(..., headers="Accept=application/json")
This results in 400 The request sent by the client was syntactically incorrect.