[jboss-user] [JBossWS] - Marshall Object List

bsisson do-not-reply at jboss.com
Wed May 21 10:19:21 EDT 2008

I'm trying to marshall a list containing objects into an XML string.  I was able to marshall a single object into an XML string but am struggling on what is needed to do a list?  

I am including an example using JBoss Tools Web Services.  It will query the database and receive a back a list of WebCalendar objects.  If I create a single object and marshall it will work.  However, I need to marshall the list so that it creates multiple entries for each object in the marshalled XML.  If you can advise I would appreciate it.

Here is an example code:

This is the class that will query the database which returns a list of WebPayCalendar objects I then try to marshall the list into an XML string:

  public String retrievePsWebPayCalendar()
           * The following example marshals an object class into an XML string which
           * is returned to the caller.  The object is an entity representing a 
           * row on the database.
          WebPayCalendarList selectCalendar =  (WebPayCalendarList) Component.getInstance("webPayCalendarList");
          // Retrieve the entire list of web pay calendar dates
          List pc = selectCalendar.getResultList();
          // For a test retrieve only the first web calendar date object
          WebPayCalendar wpc = pc.get(0);
          // Marshal the calendar information into an XML string and return it
          JAXBContext context = JAXBContext.newInstance(WebPayCalendar.class);    
          Marshaller marshaller = context.createMarshaller();    
          marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
          marshaller.marshal(pc, System.out);
          return result.getWriter().toString();
      catch (Exception e)
          return "Error:  " + e.getMessage();


This is the object Class:
package org.domain.PSWebService.entity;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;

import org.hibernate.validator.Length;

@Table(name="WEB_PAY_CALENDAR", uniqueConstraints = {@UniqueConstraint(columnNames={"RUN_ID"})})
public class WebPayCalendar implements Serializable 
    //WEB_PAY_CALENDAR Data Columns
    private String payGroup;
    private String runId;
    private java.util.Date checkDt;
    private java.util.Date payBeginDt;
    private java.util.Date payEndDt;
    private String payConfirmRun;
    public String getPayGroup()
        return payGroup;
    public void setPayGroup(String payGroup)
        this.payGroup = payGroup;
    public String getRunId()
        return runId;
    public void setRunId(String runId)
        this.runId = runId;
    public java.util.Date getCheckDt()
        return checkDt;
    public void setCheckDt(java.util.Date checkDt)
        this.checkDt = checkDt;
    public java.util.Date getPayBeginDt()
        return payBeginDt;
    public void setPayBeginDt(java.util.Date payBeginDt)
        this.payBeginDt = payBeginDt;
    public java.util.Date getPayEndDt()
        return payEndDt;
    public void setPayEndDt(java.util.Date payEndDt)
        this.payEndDt = payEndDt;
    public String getPayConfirmRun()
        return payConfirmRun;
    public void setPayConfirmRun(String payConfirmRun)
        this.payConfirmRun = payConfirmRun;

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4152353#4152353

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4152353

More information about the jboss-user mailing list