I have a simple Spring Boot web application. I'm trying to receive some data from server. The Controller returns a collection, but the browser receives empty JSON - the number of curly brackets is equals to the number of objects from server, but its content is empty.
@RestController
public class EmployeeController {
@Autowired
private EmployeeManagerImpl employeeManagerImpl;
@RequestMapping(path="/employees", method = RequestMethod.GET)
public Iterable<Employee> getAllEmployees() {
Iterable<Employee> employeesIterable = employeeManagerImpl.getAllEmployees();
return employeesIterable;
}
}
The method fires and a browser shows:
Nothing more in the console. Any ideas?
EDIT: Employee.java
@Entity
public class Employee implements Serializable{
private static final long serialVersionUID = -1723798766434132067L;
@Id
@Getter @Setter
@GeneratedValue
private Long id;
@Getter @Setter
@Column(name = "first_name")
private String firstName;
@Getter @Setter
@Column(name = "last_name")
private String lastName;
@Getter @Setter
private BigDecimal salary;
public Employee(){
}
}
I think you should use Lombok as class level instead of field level.
@Entity
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class Employee implements Serializable {}
This may solve your problem.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With