Небольшой учебный Rest веб-сервис.
Использую RestEasy + glassfish.
Методы GET для получения одной записи (работает) и всех записей (не работает).
Что сделал не так ?
Вот рабочий метод:
@GET
@Path("/person/{id}")
@Produces("application/json")
public Person getPerson(@PathParam("id") int id) {
System.out.println("get person by id");
MySQLConnection myConnection
= new MySQLConnection("jdbc:mysql://localhost/pisl", "root", "root");
Person response = myConnection.selectPerson(id);
myConnection.close();
return response;
}
Вот нерабочий метод:
@GET
@Path("/person")
@Produces("application/json")
public List<Person> getPersons() {
System.out.println("get all persons");
MySQLConnection myConnection
= new MySQLConnection("jdbc:mysql://localhost/pisl", "root", "root");
List<Person> response = myConnection.selectPersons();
myConnection.close();
return response;
}
Вот сам класс:
public class Person {
public Person() {};
@Override
public String toString() {
String json = new StringBuffer("idperson: ").append(idperson)
.append("firstname: ").append(firstName)
.append("secondname: ").append(secondName)
.append("gender: ").append(gender)
.append("dateofbirth: ").append(dateOfBirth.toString())
.append("phone: ").append(phone)
.append("city: ").append(city)
.append("faculty: ").append(faculty).toString();
return json;
}
public int getIdperson() {
return idperson;
}
public void setIdperson(int idperson) {
this.idperson = idperson;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getSecondName() {
return secondName;
}
public void setSecondName(String secondName) {
this.secondName = secondName;
}
public boolean isGender() {
return gender;
}
public void setGender(boolean gender) {
this.gender = gender;
}
public java.sql.Date getDateOfBirth() {
return dateOfBirth;
}
public void setDateOfBirth(java.sql.Date dateOfBirth) {
this.dateOfBirth = dateOfBirth;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public String getFaculty() {
return faculty;
}
public void setFaculty(String faculty) {
this.faculty = faculty;
}
private int idperson;
private String firstName;
private String secondName;
private boolean gender;
private java.sql.Date dateOfBirth;
private String phone;
private String city;
private String faculty;
}