The request sent by the client was syntactically incorrect when sending mail requests

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 work is being deleted and deleted. But whenever I make a message, I get a request sent by the client syntactically incorrect. JSON for mail request:

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

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

I use the rest-shell command to perform 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; } } 
+5
source share
3 answers

Syntactically wrong means a json issue, replace one quote with a double.

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

also check that the json keys must match your Dependent class attribute names and the data must be converted using a parser.

+10
source

Error * The request sent by the client was syntactically incorrect "** in most cases means that Jackson cannot refute (convert json string to object), since there is no default constructor.

In your case, there is no default constructor, you have a parameterized constructor that overrides the default value, and jackson cannot create an object

 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; } 

Add a default constructor to your class and everything will work

 public Dependent() { } 
+5
source

When using curl (on dos) I had the same problem. I needed to use all double quotes and therefore mask those that are inside the body part: C:> curl -H "Content-Type: application / json" -X POST -d "{\" id \ ": 1, \ "firstName \": \ "Hans \", \ "lastName \": \ "Muster \"} " http: // localhost: 8081 / persons

0
source

Source: https://habr.com/ru/post/928201/


All Articles