I change a little your class as below and ran it with java 17 and spring boot 3.0.0:
import java.time.LocalDate;
import java.time.Month;
import java.util.List;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping(path = "/api/v1/student")
public class StudentController {
@GetMapping
public List<Student> getStudents() {
return List.of (
new Student (
1L,
"Joe",
22,
LocalDate.of(2001, Month.AUGUST, 15),
"Joe@gmail.com"
)
);
}
}
And the student class as:
public class Student {
private Long id;
private String name;
private int age;
private LocalDate date;
private String mail;
public Student(Long id, String name, int age, LocalDate date, String mail) {
this.id = id;
this.name = name;
this.age = age;
this.date = date;
this.mail = mail;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public LocalDate getDate() {
return date;
}
public void setDate(LocalDate date) {
this.date = date;
}
public String getMail() {
return mail;
}
public void setMail(String mail) {
this.mail = mail;
}
}
Calling the url http://localhost:8080/api/v1/student I get a json response as below:
[{"id":1,"name":"Joe","age":22,"date":"2001-08-15","mail":"Joe@gmail.com"}]