I have no idea what is happening but for some reason the is prefix from my property is being removed.
I have even removed the annotations from Lombok and manually created the getters and setters but for some reason, I get this weird error.
I have a prop called isAuthenticated, that must return to the browser, for some reason, I am getting authenticated.
Here is the code: //The end point in the API: @GetMapping("/auth") public EmployeeState getEmployeeState(HttpServletRequest request) { return employeeService.getEmployeeState(request.getSession()); }
The Service method:
public EmployeeState getEmployeeState(HttpSession session) {
EmployeeState employeeState = new EmployeeState();
employeeState.setIsAuthenticated(SecurityContextHolder.getContext().getAuthentication().isAuthenticated());
if (employeeState.isAuthenticated()){
if (session.getAttribute("employeeNumber") != null){
Employee employee = employeeRepository.getEmployeeByEmployeeNumber(session.getAttribute("employeeNumber").toString()).get();
employeeState.setFirstName(employee.getFirstName());
employeeState.setLastName(employee.getLastName());
employeeState.setEmployeeNumber(employee.getEmployeeNumber());
}
}
return employeeState;
}
This is the model, the response is supposed to return:
public class EmployeeState {
private String firstName;
private String lastName;
private String employeeNumber;
private boolean isAuthenticated;
public EmployeeState(){
}
public EmployeeState(String firstName, String lastName, String employeeNumber, boolean isAuthenticated) {
this.firstName = firstName;
this.lastName = lastName;
this.employeeNumber = employeeNumber;
this.isAuthenticated = isAuthenticated;
}
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 getEmployeeNumber() {
return employeeNumber;
}
public void setEmployeeNumber(String employeeNumber) {
this.employeeNumber = employeeNumber;
}
public boolean isAuthenticated() {
return isAuthenticated;
}
public void setIsAuthenticated(boolean authenticated) {
isAuthenticated = authenticated;
}
}
Result in the browser:
Edit 1:
I tried to add the @JsonProperty annotation, and now I get two properties:
public class EmployeeState {
private String firstName;
private String lastName;
private String employeeNumber;
@JsonProperty(value = "isAuthenticated")
private boolean isAuthenticated;
public EmployeeState(){
}
public EmployeeState(String firstName, String lastName, String employeeNumber, boolean isAuthenticated) {
this.firstName = firstName;
this.lastName = lastName;
this.employeeNumber = employeeNumber;
this.isAuthenticated = isAuthenticated;
}
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 getEmployeeNumber() {
return employeeNumber;
}
public void setEmployeeNumber(String employeeNumber) {
this.employeeNumber = employeeNumber;
}
public boolean isAuthenticated() {
return isAuthenticated;
}
public void setIsAuthenticated(boolean authenticated) {
isAuthenticated = authenticated;
}
}
Now there are two properties: