users@jaxb.java.net

Re: Sending arrays in objects.

From: Wolfgang Laun <wolfgang.laun_at_gmail.com>
Date: Tue, 27 Jan 2009 09:36:32 +0100

What's the JAXB version you're using? How is the schema generated
that you've posted? (BTW: There is no element with the name
"ArrayOf_xsd_String". Did you post the modified version?)

I'm not familiar with the web service development environment but I've
experimented with JAXB as it comes with /usr/java/jdk1.6.0_03.
I've used a class containing an array DataSetType[] datasets,
and this one with an attribute String[] columns. It appears that
JAXB is capable of handling this without a hitch:

public class DataSetType {
    private int id;
    private String[] columns;
    public DataSetType(){}

    public int getId(){... }
    public void setId( int value ){...}
    public String[] getColumns(){ ... }
    public void setColumns( String[] value ){ ... }
}
//===
@XmlRootElement
public class ResponseType {
    private DataSetType[] datasets;
    public ResponseType(){}
    public DataSetType[] getDatasets(){...}
    public void setDatasets( DataSetType[] value ){...}
}
//===

This is the generated schema (jdk1.6.0_03/bin/schemagen):

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<xs:schema version="1.0" xmlns:xs="http://www.w3.org/2001/XMLSchema">

  <xs:element name="responseType" type="responseType"/>
  <xs:complexType name="dataSetType">
    <xs:sequence>
      <xs:element name="columns" type="xs:string"
                  nillable="true" maxOccurs="unbounded" minOccurs="0"/>
      <xs:element name="id" type="xs:int"/>
    </xs:sequence>
  </xs:complexType>

  <xs:complexType name="responseType">
    <xs:sequence>
      <xs:element name="datasets" type="dataSetType"
                  nillable="true" maxOccurs="unbounded" minOccurs="0"/>
    </xs:sequence>
  </xs:complexType>
</xs:schema>

//===
If I marshal a simple "response", I get

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<responseType>
    <datasets>
        <columns>col1_1</columns>
        <columns>col1_2</columns>
        <id>1</id>
    </datasets>
    <datasets>
        <columns>col2_1</columns>
        <columns>col2_2</columns>
        <columns>col2_3</columns>
        <id>2</id>
    </datasets>
</responseType>


On Mon, Jan 26, 2009 at 11:22 PM, Szmg <mate.szvoboda_at_gmail.com> wrote:

>
> I'm trying to make a webservice that returns an array of objects, which
> contains another array of objects.
>
> Everything works fine, when I hack the wsdl manually.
> How can I make it work without modify it?
>
> I'm using
> Eclipse 3.4 for Java EE,
> Axis 1.4,
> Glassfish v2 UR2, and
> Eclipse's Web Services Explorer for testing.
>
> My service method looks like this:
> public DataSet[] getDataSet(User owner) {
> DataSet[] res = new DataSet[2];
> res[0] = new DataSet();
> DataSet ds = res[0];
> ds.setName("DataSet1");
> ds.setDescription("No desc");
> ds.setIsDefault(false);
> String[] ss = {"One", "Two"};
> ds.setColumns(ss);
> return res;
> }
>
> DataSet is a simple JavaBean:
>
> public class DataSet implements java.io.Serializable {
> private String name;
> private String description;
> private boolean isDefault;
> private String[] columns;
>
> public String getName() {
> return name;
> }
> public void setName(String name) {
> this.name = name;
> }
> public String getDescription() {
> return description;
> }
> public void setDescription(String description) {
> this.description = description;
> }
> public boolean getIsDefault() {
> return isDefault;
> }
> public void setIsDefault(boolean isDefault) {
> this.isDefault = isDefault;
> }
> public String[] getColumns() {
> return columns;
> }
> public void setColumns(String[] columns) {
> this.columns = columns;
> }
>
> }
>
> Generated WSDL part:
> <element name="getDataSetResponse">
> <complexType>
> <sequence>
> <element maxOccurs="unbounded" name="getDataSetReturn"
> type="impl:DataSet"/>
> </sequence>
> </complexType>
> </element>
> <complexType name="ArrayOf_xsd_string">
> <sequence>
> <element maxOccurs="unbounded" minOccurs="0" name="item"
> type="xsd:string"/>
> </sequence>
> </complexType>
> <complexType name="DataSet">
> <sequence>
> <element name="columns" nillable="true"
> type="impl:ArrayOf_xsd_string"/>
> <element name="description" nillable="true" type="xsd:string"/>
> <element name="isDefault" type="xsd:boolean"/>
> <element name="name" nillable="true" type="xsd:string"/>
> </sequence>
> </complexType>
>
>
> It works when I set the name of the element of "ArrayOf_xsd_string" to
> "columns". (<element maxOccurs="unbounded" minOccurs="0" name="columns"
> type="xsd:string"/>)
>
>
>
>
> SOAP response:
> - <soapenv:Envelope
> xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
> xmlns:xsd="http://www.w3.org/2001/XMLSchema"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
> - <soapenv:Body>
> - <getDataSetResponse xmlns="http://score.com">
> - <getDataSetReturn>
> - <columns>
> <columns>One</columns>
> <columns>Two</columns>
> </columns>
> <description>No desc</description>
> <isDefault>false</isDefault>
> <name>DataSet1</name>
> </getDataSetReturn>
> <getDataSetReturn xsi:nil="true" />
> </getDataSetResponse>
> </soapenv:Body>
> </soapenv:Envelope>
>
>
>
> Any idea?
> --
> View this message in context:
> http://www.nabble.com/Sending-arrays-in-objects.-tp21674015p21674015.html
> Sent from the java.net - jaxb users mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net
> For additional commands, e-mail: users-help_at_jaxb.dev.java.net
>
>