0
Good night,
I’m trying to compile a code to run a simple Rest in spring mvc, but found with the error "The request sent by the client was syntactically incorrect."
Class Controller
package br.com.aprendendorest.controllers;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import br.com.aprendendorest.models.cliente;
import br.com.aprendendorest.repository.clienteRepository;
@RestController
public class clienteController {
    @Autowired
    clienteRepository clienteService;
    @GetMapping("/cliente")
    public ResponseEntity<List<cliente>> listCliente() {
        System.out.println("Entro Get");
        List<cliente> clientes = clienteService.listAll();
        return new ResponseEntity<List<cliente>>(clientes, HttpStatus.OK);
    }
    @PostMapping("/cliente")
    public ResponseEntity<cliente> creatCliente(@RequestBody cliente cli) {
        System.out.println("Entro no POST");
        System.out.println("ID: " + cli.getId() + ", NOME: " + cli.getNome() + ", EMAIL: " + cli.getEmail());
        clienteService.addCliente(cli);
        return new ResponseEntity<cliente>(cli, HttpStatus.CREATED);
    }
}
Model class
package br.com.aprendendorest.models;
public class cliente {
    private Integer id;
    private String nome;
    private String email;
    public Integer getId() {
        return id;
    }
    public void setId(Integer id) {
        this.id = id;
    }
    public String getNome() {
        return nome;
    }
    public void setNome(String nome) {
        this.nome = nome;
    }
    public String getEmail() {
        return email;
    }
    public void setEmail(String email) {
        this.email = email;
    }
    public cliente(int id, String nome, String email) {
        this.id = id;
        this.nome = nome;
        this.email = email;
    }
}
POST JSON
{
    "id": 5,
    "nome": "Marcos",
    "email": "teste"
}
						
How the requisition is being made?
– Leonardo Villela
Through Postman, using the above json, with the content type application/json.
– Marcos Paulo
Okay, share a print of your request in Postman
– Leonardo Villela
I edited the Post @Leonardo Villela, I do not understand because the fields and types are correct.
– Marcos Paulo