After doing a big deal of research on the topic I decided to ask in here. I am getting all null properties to the POJO/Model which is supposed to get values from the JSON I am posting from the Angular 2 Front end. Here is the rest controller method:
@RequestMapping(value = "/employees/update", method = RequestMethod.POST, consumes = "application/json")
public String allEmployees( @RequestBody Employee emp){
return "";
}
The following is the POJO/Model/Hibernate Entity:
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(nullable = false, updatable = false)
private Long id;
private String firstname;
private String lastname;
private String department;
public Employee(){}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
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 getDepartment() {
return department;
}
public void setDepartment(String department) {
this.department = department;
}
The following is the Angular 2 Service method:
updateEmployee(emp:Employee){
let url: string = "http://localhost:8080/api/employees/update";
let headers = new Headers();
headers.append('Content-Type', 'application/json');
return this.http.post(url, {emp}, {headers: headers, withCredentials: true }).map(res => res.json());
}
and the Employee interface of Angular 2:
export interface Employee{
id: number;
firstname: string;
lastname: string;
department: string;
}
What am I doing wrong? I have searched for similar issues but none I found applies to my case. Thank you!