Nithyananth Nithyananth -4 years ago 89
reST (reStructuredText) Question

Unexpected 'S' in Postman on consuming REST Api

I wrote very basic REST service in SpringBootApplication. When I tried to hit the api I am getting response like

Unexpected 'S'

This is my api,

public class CreateProjectApi {

@RequestMapping(value = "/createProject",
produces = { "application/json" },
consumes = { "application/json" },
method = RequestMethod.GET)
public ResponseEntity<String> createProj() {
String s = "Success...";
return new ResponseEntity<String>(s, HttpStatus.OK);


This is my POM.XML,

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="" xmlns:xsi=""


<description>Demo project for Spring Boot</description>

<relativePath /> <!-- lookup parent from repository -->




<!-- Setup Spring MVC & REST, use Embedded Tomcat -->



I am hitting the api through postman with
in header. But I am getting Unexpected 'S' as response. I have followed this link unexpected 's' in response of restful service but I didnt get any solution from that. Can anyone help me out in this?

Answer Source

As explained in the comments by both user7790438 and nbrooks, the issue is that your response will be plain text (Success...), even though you tell it to load JSON (by providing the Content-Type: application/json header).

To return JSON, you should return some kind of object, for example, you could create a ProjectStatus class like this:

public class ProjectStatus {
    private String status;

    public ProjectStatus(String status) {
        this.status = status;

    public String getStatus() {
        return status;

Now, in your REST controller you should return a ResponseEntity<ProjectStatus>, like this:

return new ResponseEntity<ProjectStatus>(new ProjectStatus("Success..."), HttpStatus.OK);

This will result in the following JSON when you use Postman:

{"status": "Success..."}

You can pretty much return any object you'd like. An example would be to return the created project in your response.

Alternatively, if you don't need JSON, you could provide the Content-Type: text/plain header.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download