the request sent by the client was syntactically incorrect when sending post requests

Vishwa picture Vishwa · Feb 26, 2014 · Viewed 27.6k times · Source

The method in myController looks like this

@RequestMapping(value="/{processId}/dependents", method=RequestMethod.POST,consumes="application/json")
@ResponseBody
public Dependents postdependent(@ModelAttribute ProcessContext process,@RequestBody Dependent dependent) {
    return process.getDependents().addDependent(dependent);
}

My gets and delete work perfectly. But whenever I do a post I am getting the request sent by the client was syntactically incorrect. JSON for post request:

"{
   'dependentId' : '1003',
   'firstName'   : 'Vishu',
   'lastName'    : 'poodari',
   'birthDate'   : '1970/04/15'
}"

Please I tried all combinations by using single quotes, doubles quotes everything.

I am using rest-shell for doing the operations.

Please find my Dependent Class

public class Dependent {
    private String dependentId;
    private String firstName;
    private String lastName;
    private String birthDate;
    @JsonCreator
    public Dependent(@JsonProperty("dependentId") String dependentId, @JsonProperty("firstName") String firstName, @JsonProperty("lastName")String lastName,
            @JsonProperty("birthDate") String birthDate) {
        this.dependentId = dependentId;
        this.firstName = firstName;
        this.lastName = lastName;
        this.birthDate = birthDate;
    }
    public String getDependentId() {
        return dependentId;
    }
    public void setDependentId(String dependentId) {
        this.dependentId = dependentId;
    }
    public String getFirstName() {
        return firstName;
    }
    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }
    public String getLastName() {
        return lastName;
    }
    public void setLastName(String lastName) {
        this.lastName = lastName;
    }
    public String getBirthDate() {
        return birthDate;
    }
    public void setBirthDate(String birthDate) {
        this.birthDate = birthDate;
    }
}

Answer

RPaul picture RPaul · Feb 28, 2014

syntactically incorrect means problem with the json,please replace the single quote with double.

{"dependentId" : "1003",
   "firstName"   : "Vishu",
   "lastName"    : "poodari",
   "birthDate"   : "1970/04/15"
}

also check the json keys should match with your Dependent class attribute names, and the data should be convertible by the parser.