No worries :-)
----- Original Message -----
From: "Raphaël Flores" <[email protected]>
To: <[email protected]>
Sent: Wednesday, August 26, 2009 12:32 PM
Subject: Re: Binding of List<Object> returns empty
Erf.. Sooo stupid ! Silly copy & paste. -_-'
Thanks Sergey.
Sergey Beryozkin a écrit :
Hi
please change setProjects to setBiosources and it will work...It's a jaxb
issue, I'd call it a JAXB restriction...
cheers, Sergey
Raphaël Flores-2 wrote:
Hello,
Whatever I do, I can't get a correct binding with List of objects
(biosources), it always returns an empty list while Biosource, which are
elements of the list, are correctly binded when taken alone.
Here is my List class:
==========================
import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement(name = "BiosourcesList")
public class BiosourcesList {
List<Biosource> biosources;
public BiosourcesList() {
}
public BiosourcesList(List<Biosource> biosources) {
this.biosources = biosources;
}
public List<Biosource> getBiosources() {
return this.biosources;
}
public void setProjects(final List<Biosource> biosources) {
this.biosources = biosources;
}
}
==========================
Here is the alone element class:
------------------------------------
import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement(name = "Biosource")
public class Biosource extends ProticObject {
private Project project;
private String biosourceName;
private Date sowingDate;
private String remark;
private Long startingMaterialTermId;
private boolean isPrivate;
public Biosource() {
}
public Biosource(int dbId, int projectId, int logId,
UserAccessVerification userAccessVerification) {
super(dbId, projectId, logId, userAccessVerification);
}
other constructors...
getters and setters...
}
------------------------------------
here is the frontend method:
==========================
@GET
@Path("/projects/{id}/biosources")
@Produces("application/xml")
public Response getBiosources(@PathParam("id") int id, @Context
HttpHeaders headers) throws Exception {
Project project = (Project)this.getProject(id,
headers).getEntity();
BiosourcesList biosourcesList = factory.getBiosources(project);
for (int i = 0; i < biosourcesList.getBiosources().size(); i++) {
System.out.println("Biosource name n°" + i + " is: \"" +
biosourcesList.getBiosources().get(i).getBiosourceName()
+ "\" and it ID is: " +
biosourcesList.getBiosources().get(i).getDbId());
}
return
Response.ok(biosourcesList).status(HttpStatus.SC_OK).build();
}
==========================
The biosourcesList is correctly constructed as I can see the "for loop"
showing each biosource with name and ID, but when I check this url (with :
http://localhost:8080/projects/127/biosources
I get an empty list of biosources:
------------------------------------
<?xml version="1.0" encoding="UTF-8" standalone="yes"?><BiosourcesList/>
------------------------------------
It might not be a big error I think, but I can't see what is the
problem. Help would be great.
Thanks,
--
Raphaël Flores
--
Raphaël Flores
Téléphone : 01 69 33 23 76
UMR de Génétique Végétale, INRA, Univ. Paris-Sud,
CNRS, AgroParisTech, F-91190 Gif-sur-Yvette, France