i have a problem with rest and method post on my controler i have this 2 class the first is user in my class user i have my class with the getters and setter and a default contructor because for the finally I would like use Hibernate .:
@Entity
@Table(name="Utilisateur") // mapping with hibernate (but not using in this situation)
public class User {
@Id
private long id;
@Column(name="nom")
private String nom;
@Column(name="prenom")
private String prenom;
@Column(name="admin")
private boolean admin;
@Column(name="actif")
private boolean actif;
@Column(name="logins")
private String logins;
@Column(name="email")
private String email;
@Column(name="naissance")
private String naissance;
@Column(name="pwd")
private String pwd;
@Column(name="compte")
private String compte;
public User(){
}
/*
with getter and setter.
*/
}
and my class controler (User controller) : is using for make the api principally post api .
@RestController
public class UserController {
@RequestMapping(
value="/api/greetings/post",
method = RequestMethod.POST,
consumes = MediaType.APPLICATION_JSON_VALUE,
produces=MediaType.APPLICATION_JSON_VALUE
)
@ResponseBody
public ResponseEntity<User> getByEmail(@RequestBody User user){
if(user==null){
return new ResponseEntity<User>(HttpStatus.INTERNAL_SERVER_ERROR);
}
return new ResponseEntity<User>(user, HttpStatus.OK);
}
and i get this erreur I am using postman for make the query and in parameter of my query I send this Json query :
{"id":"3","nom":"Gille","prenom":"Laurent","admin":"1","actif":"0","logins":"gilaur","email":""toto@hotmail.com,"naissance":"1990/09/09","pwd":"gal","compte":"autre"}
And i get this error :
{"timestamp":1457906727481,"status":415,"error":"Unsupported Media Type","exception":"org.springframework.web.HttpMediaTypeNotSupportedException","message":"Content type 'text/plain;charset=UTF-8' not supported","path":"/api/greetings/post/"}
Thank you
you are change headers content-type
application/json
in Postman because you try settext/plain