Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring REST Controller returns JSON with empty data [closed]

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:

enter image description here

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(){

    }
}
like image 619
Radziasss Avatar asked Oct 07 '16 10:10

Radziasss


1 Answers

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.

like image 95
Pedro Tavares Avatar answered Sep 21 '22 11:09

Pedro Tavares