DEBENDRA DHINDA
DEBENDRA DHINDA

Reputation: 1193

How can i specify headers as application/json using JSONDOC

I am using Spring4 to design my REST API. But while I am documenting it using JsonDoc, it is giving me an error as:

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

Apache Tomcat/7.0.62

", "status": 415, "statusText": "Unsupported Media Type" }

@ApiMethod
@ApiHeaders(headers={ @ApiHeader(name="Content-Type", allowedvalues="application/json",description="application/json")})
@RequestMapping(value="/test" ,method=RequestMethod.POST)   
public @ApiResponseObject  @ResponseBody ResponseMessage test(@ApiBodyObject @RequestBody TestDto test){
    System.out.println(test.getId());
    return testService.addTestMessage("hello demo");
}

How can I test it?

Upvotes: 0

Views: 419

Answers (2)

user11425844
user11425844

Reputation:

Check your content type and check your payload format.

There might be some attribute which are not matching.

Upvotes: 0

Vijay Kumar Rajput
Vijay Kumar Rajput

Reputation: 1121

I believe It has nothing to do with JSONDoc. You need to check if you are sending valid Content-Type like application/json.

Please also check TestDto JSON representation is correctly converting to JAVA object. Spring throws this error if your JSON string is not able to convert java object.

If you are using Jackson API, You can use below sample to get exception and see cause.

    String myJsonString="Your JSON String";
    ObjectMapper mapper = new ObjectMapper();
    try {
        mapper.readValue(myJsonString,TestDto.class);
    } catch (JsonParseException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (JsonMappingException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

Upvotes: 0

Related Questions