Re: Binding of List returns empty

Wed, 26 Aug 2009 03:25:14 -0700

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
> 
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Binding-of-List%3CObject%3E-returns-empty-tp25134370p25150172.html
Sent from the cxf-user mailing list archive at Nabble.com.

Reply via email to