I have an object which gets two parameters through a json POST request to create a new entry in the database and I get this error:
"Type definition error: [simple type, class ffuentese.rest_example.Persona]; nested exception is com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Cannot construct instance of
ffuentese.rest_example.Persona
(no Creators, like default construct, exist): cannot deserialize from Object value (no delegate- or property-based Creator) at [Source: (PushbackInputStream); line: 2, column: 3]",
This is the object:
@Entity
public class Persona {
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private Integer id;
private String nombre;
private String apellido;
public Persona(String nombre, String apellido) {
this.nombre = nombre;
this.apellido = apellido;
}
public Integer getId() {
return id;
}
public String getNombre() {
return nombre;
}
public void setNombre(String nombre) {
this.nombre = nombre;
}
public String getApellido() {
return apellido;
}
public void setApellido(String apellido) {
this.apellido = apellido;
}
}
This is the controller method:
@PostMapping(path="/persona")
public @ResponseBody String addPersona(@RequestBody Persona p) {
personaRepository.save(p);
return "success";
}