Java Array string

I am connecting to a WCF service and it's expecting me to send an

Array of Array of string

I am creating a multi dimensional array in java and assigning it to that value but the WCF sees it as null.

on the WCF the function it is expecting an mutidimentional array

String [10][10]

any suggestions

LVL 9
JonMnyAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

CEHJCommented:
>>I am creating a multi dimensional array in java and assigning it to that value

How? Please post code
0
JonMnyAuthor Commented:
Java code
                 merge = new Merge();
                String[] fieldNames = new String[4];
                String[][] fieldValues = new String[1][4];
                String[] values = new String[4];
                fieldNames[0] = "Header1";
                fieldNames[1] = "Header2";
                fieldNames[2] = "Header3";
                fieldNames[3] = "Header4";
               
                values[0] = "Row1Value1";
                values[1]= "Row1Value2";
                values[2]= "Row1Value3";
                values[3]= "Row1Value4";
             
                fieldValues[0][0]=values[0];
                fieldValues[0][1]=values[1];
                fieldValues[0][2]=values[2];
                fieldValues[0][3]=values[3];
 
                mergeData.setFieldNames(fieldNames);
           mergeData.setFieldValues(fieldValues);
           merge.setMergeData(mergeData);
         po.setMerge(merge);
   
  //Create Job    
  Job job = new Job();

 
 
WSDL (Section)
 

<xs:element minOccurs="0" name="MergeData" nillable="true" type="tns:MergeData" />
<xs:element minOccurs="0" name="MergeFile" nillable="true" type="tns:MergeFile" />
</xs:sequence>
</xs:complexType>
<xs:element name="Merge" nillable="true" type="tns:Merge" />
+ <xs:complexType name="MergeData">
- <xs:sequence>
<xs:element minOccurs="0" name="FieldNames" nillable="true" type="q1:ArrayOfstring" xmlns:q1="http://schemas.microsoft.com/2003/10/Serialization/Arrays" />
<xs:element minOccurs="0" name="FieldValues" nillable="true" type="q2:ArrayOfArrayOfstring" xmlns:q2="http://schemas.microsoft.com/2003/10/Serialization/Arrays" />  
 
 
When submitted the Field Names "go through" the Merge Data is empty
0
CEHJCommented:
>>mergeData

is not shown in your code - where do you initialize it?
0
HTML5 and CSS3 Fundamentals

Build a website from the ground up by first learning the fundamentals of HTML5 and CSS3, the two popular programming languages used to present content online. HTML deals with fonts, colors, graphics, and hyperlinks, while CSS describes how HTML elements are to be displayed.

CEHJCommented:
>>values[0] = "Row1Value1";

In the above, btw, 'values' is redundant. You can do


fieldValues[0][0] = "Row1Value1"; //etc

Open in new window

0
JonMnyAuthor Commented:
Merge merge = new Merge();
     MergeData mergeData = new MergeData();
 
Below is the auto generated Java code
 

/**
 * MergeData.java
 *
 * This file was auto-generated from WSDL
 * by the Apache Axis 1.4 Apr 22, 2006 (06:55:48 PDT) WSDL2Java emitter.
 */
package org.datacontract.schemas._2004._07.Rimage_Web_Service;
public class MergeData  implements java.io.Serializable {
    private java.lang.String[] fieldNames;
    private java.lang.String[][] fieldValues;
    public MergeData() {
    }
    public MergeData(
           java.lang.String[] fieldNames,
           java.lang.String[][] fieldValues) {
           this.fieldNames = fieldNames;
           this.fieldValues = fieldValues;
    }

    /**
     * Gets the fieldNames value for this MergeData.
     *
     * @return fieldNames
     */
    public java.lang.String[] getFieldNames() {
        return fieldNames;
    }

    /**
     * Sets the fieldNames value for this MergeData.
     *
     * @param fieldNames
     */
    public void setFieldNames(java.lang.String[] fieldNames) {
        this.fieldNames = fieldNames;
    }

    /**
     * Gets the fieldValues value for this MergeData.
     *
     * @return fieldValues
     */
    public java.lang.String[][] getFieldValues() {
        return fieldValues;
    }

    /**
     * Sets the fieldValues value for this MergeData.
     *
     * @param fieldValues
     */
    public void setFieldValues(java.lang.String[][] fieldValues) {
        this.fieldValues = fieldValues;
    }
    private java.lang.Object __equalsCalc = null;
    public synchronized boolean equals(java.lang.Object obj) {
        if (!(obj instanceof MergeData)) return false;
        MergeData other = (MergeData) obj;
        if (obj == null) return false;
        if (this == obj) return true;
        if (__equalsCalc != null) {
            return (__equalsCalc == obj);
        }
        __equalsCalc = obj;
        boolean _equals;
        _equals = true && 
            ((this.fieldNames==null && other.getFieldNames()==null) ||
             (this.fieldNames!=null &&
              java.util.Arrays.equals(this.fieldNames, other.getFieldNames()))) &&
            ((this.fieldValues==null && other.getFieldValues()==null) ||
             (this.fieldValues!=null &&
              java.util.Arrays.equals(this.fieldValues, other.getFieldValues())));
        __equalsCalc = null;
        return _equals;
    }
    private boolean __hashCodeCalc = false;
    public synchronized int hashCode() {
        if (__hashCodeCalc) {
            return 0;
        }
        __hashCodeCalc = true;
        int _hashCode = 1;
        if (getFieldNames() != null) {
            for (int i=0;
                 i<java.lang.reflect.Array.getLength(getFieldNames());
                 i++) {
                java.lang.Object obj = java.lang.reflect.Array.get(getFieldNames(), i);
                if (obj != null &&
                    !obj.getClass().isArray()) {
                    _hashCode += obj.hashCode();
                }
            }
        }
        if (getFieldValues() != null) {
            for (int i=0;
                 i<java.lang.reflect.Array.getLength(getFieldValues());
                 i++) {
                java.lang.Object obj = java.lang.reflect.Array.get(getFieldValues(), i);
                if (obj != null &&
                    !obj.getClass().isArray()) {
                    _hashCode += obj.hashCode();
                }
            }
        }
        __hashCodeCalc = false;
        return _hashCode;
    }
    // Type metadata
    private static org.apache.axis.description.TypeDesc typeDesc =
        new org.apache.axis.description.TypeDesc(MergeData.class, true);
    static {
        typeDesc.setXmlType(new javax.xml.namespace.QName("http://schemas.datacontract.org/2004/07/Rimage.Web.Service", "MergeData"));
        org.apache.axis.description.ElementDesc elemField = new org.apache.axis.description.ElementDesc();
        elemField.setFieldName("fieldNames");
        elemField.setXmlName(new javax.xml.namespace.QName("http://schemas.datacontract.org/2004/07/Rimage.Web.Service", "FieldNames"));
        elemField.setXmlType(new javax.xml.namespace.QName("http://www.w3.org/2001/XMLSchema", "string"));
        elemField.setMinOccurs(0);
        elemField.setNillable(true);
        elemField.setItemQName(new javax.xml.namespace.QName("http://schemas.microsoft.com/2003/10/Serialization/Arrays", "string"));
        typeDesc.addFieldDesc(elemField);
        elemField = new org.apache.axis.description.ElementDesc();
        elemField.setFieldName("fieldValues");
        elemField.setXmlName(new javax.xml.namespace.QName("http://schemas.datacontract.org/2004/07/Rimage.Web.Service", "FieldValues"));
        elemField.setXmlType(new javax.xml.namespace.QName("http://schemas.microsoft.com/2003/10/Serialization/Arrays", "ArrayOfstring"));
        elemField.setMinOccurs(0);
        elemField.setNillable(true);
        elemField.setItemQName(new javax.xml.namespace.QName("http://schemas.microsoft.com/2003/10/Serialization/Arrays", "ArrayOfstring"));
        typeDesc.addFieldDesc(elemField);
    }
    /**
     * Return type metadata object
     */
    public static org.apache.axis.description.TypeDesc getTypeDesc() {
        return typeDesc;
    }
    /**
     * Get Custom Serializer
     */
    public static org.apache.axis.encoding.Serializer getSerializer(
           java.lang.String mechType,
           java.lang.Class _javaType,  
           javax.xml.namespace.QName _xmlType) {
        return
          new  org.apache.axis.encoding.ser.BeanSerializer(
            _javaType, _xmlType, typeDesc);
    }
    /**
     * Get Custom Deserializer
     */
    public static org.apache.axis.encoding.Deserializer getDeserializer(
           java.lang.String mechType,
           java.lang.Class _javaType,  
           javax.xml.namespace.QName _xmlType) {
        return
          new  org.apache.axis.encoding.ser.BeanDeserializer(
            _javaType, _xmlType, typeDesc);
    }
}
 
 
 
0
CEHJCommented:
You may find, as is most the case where serialization is  involved, only the no-arg ctor gets called
0
JonMnyAuthor Commented:
I am calling the no arg constructors.
0
CEHJCommented:
Can you post the actual error message you're getting?
0
JonMnyAuthor Commented:
there is not an error generated, the problem is the resulting soap message has a "" instead of the values from the array
0
JonMnyAuthor Commented:
Ok,
I have more information attached is a trace dump one from .net that works and the java that does not.
 
 
Java:

<ns1:FieldNames>
<ns2:string xmlns:ns2="http://schemas.microsoft.com/2003/10/Serialization/Arrays">Header1</ns2:string>
<ns3:string xmlns:ns3="http://schemas.microsoft.com/2003/10/Serialization/Arrays">Header2</ns3:string>
<ns4:string xmlns:ns4="http://schemas.microsoft.com/2003/10/Serialization/Arrays">Header3</ns4:string>
<ns5:string xmlns:ns5="http://schemas.microsoft.com/2003/10/Serialization/Arrays">Header4</ns5:string>
</ns1:FieldNames>
<ns1:FieldValues>
<ns6:ArrayOfstring xmlns:ns6="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
<ns6:ArrayOfstring>Row1Value1</ns6:ArrayOfstring>
<ns6:ArrayOfstring>Row1Value2</ns6:ArrayOfstring>
<ns6:ArrayOfstring>Row1Value3</ns6:ArrayOfstring>
<ns6:ArrayOfstring>Row1Value4</ns6:ArrayOfstring>
</ns6:ArrayOfstring>
 
 
.net

<a:MergeData>
<a:FieldNames xmlns:b="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
<b:string>Header1</b:string>
<b:string>Header2</b:string>
<b:string>Header3</b:string>
<b:string>Header4</b:string>
</a:FieldNames>
<a:FieldValues xmlns:b="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
<b:ArrayOfstring>
<b:string>Row1Value1</b:string>
<b:string>Row1Value2</b:string>
<b:string>Row1Value3</b:string>
<b:string>Row1Value4</b:string>
</b:ArrayOfstring>
</a:FieldValues>
</a:MergeData>
 
0
CEHJCommented:
MergeData has not been deserialized properly. Probably for the reasons i already gave you
0
CEHJCommented:
Sorry - ignore that last comment
0
JonMnyAuthor Commented:
Soap end point class

qName = new javax.xml.namespace.QName("http://schemas.microsoft.com/2003/10/Serialization/Arrays", "ArrayOfArrayOfstring");
cachedSerQNames.add(qName);
cls = java.lang.String[][].class;
cachedSerClasses.add(cls);
qName = new javax.xml.namespace.QName("http://schemas.microsoft.com/2003/10/Serialization/Arrays", "ArrayOfstring");
qName2 = new javax.xml.namespace.QName("http://schemas.microsoft.com/2003/10/Serialization/Arrays", "ArrayOfstring");
cachedSerFactories.add(new org.apache.axis.encoding.ser.ArraySerializerFactory(qName, qName2));
cachedDeserFactories.add(new org.apache.axis.encoding.ser.ArrayDeserializerFactory());
qName = new javax.xml.namespace.QName("http://schemas.microsoft.com/2003/10/Serialization/Arrays", "ArrayOfstring");
cachedSerQNames.add(qName);
cls = java.lang.String[].class;
cachedSerClasses.add(cls);
qName = new javax.xml.namespace.QName("http://www.w3.org/2001/XMLSchema", "string");
qName2 = new javax.xml.namespace.QName("http://schemas.microsoft.com/2003/10/Serialization/Arrays", "string");
cachedSerFactories.add(new org.apache.axis.encoding.ser.ArraySerializerFactory(qName, qName2));
cachedDeserFactories.add(new org.apache.axis.encoding.ser.ArrayDeserializerFactory());
 
Mergedata class

typeDesc.setXmlType(new javax.xml.namespace.QName("http://schemas.datacontract.org/2004/07/test.Web.Service", "MergeData"));
org.apache.axis.description.ElementDesc elemField = new org.apache.axis.description.ElementDesc();
elemField.setFieldName("fieldNames");
elemField.setXmlName(new javax.xml.namespace.QName("http://schemas.datacontract.org/2004/07/test.Web.Service", "FieldNames"));
elemField.setXmlType(new javax.xml.namespace.QName("http://www.w3.org/2001/XMLSchema", "string"));
elemField.setMinOccurs(0);
elemField.setNillable(true);
elemField.setItemQName(new javax.xml.namespace.QName("http://schemas.microsoft.com/2003/10/Serialization/Arrays", "string"));
typeDesc.addFieldDesc(elemField);
elemField = new org.apache.axis.description.ElementDesc();
elemField.setFieldName("fieldValues");
elemField.setXmlName(new javax.xml.namespace.QName("http://schemas.datacontract.org/2004/07/test.Web.Service", "FieldValues"));
elemField.setXmlType(new javax.xml.namespace.QName("http://schemas.microsoft.com/2003/10/Serialization/Arrays", "string")); --Chaged this
elemField.setMinOccurs(0);
elemField.setNillable(true);
elemField.setItemQName(new javax.xml.namespace.QName("http://schemas.microsoft.com/2003/10/Serialization/Arrays", "ArrayOfstring"));
typeDesc.addFieldDesc(elemField);
}
 

I modified the serilizer above and got the following

<ns1:MergeData>
<ns1:FieldNames>
<ns2:string xmlns:ns2="http://schemas.microsoft.com/2003/10/Serialization/Arrays">Header1</ns2:string>
<ns3:string xmlns:ns3="http://schemas.microsoft.com/2003/10/Serialization/Arrays">Header2</ns3:string>
<ns4:string xmlns:ns4="http://schemas.microsoft.com/2003/10/Serialization/Arrays">Header3</ns4:string>
<ns5:string xmlns:ns5="http://schemas.microsoft.com/2003/10/Serialization/Arrays">Header4</ns5:string>
</ns1:FieldNames>
<ns1:FieldValues xsi:type="ns6:ArrayOfArrayOfstring" xmlns:ns6="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
<ns6:ArrayOfstring xsi:type="ns6:ArrayOfstring">
<ns6:ArrayOfstring xsi:type="xsd:string">Row1Value1</ns6:ArrayOfstring>
<ns6:ArrayOfstring xsi:type="xsd:string">Row1Value2</ns6:ArrayOfstring>
<ns6:ArrayOfstring xsi:type="xsd:string">Row1Value3</ns6:ArrayOfstring>
<ns6:ArrayOfstring xsi:type="xsd:string">Row1Value4</ns6:ArrayOfstring>
</ns6:ArrayOfstring>
</ns1:FieldValues>
</ns1:MergeData>
</ns1:Merge>
</ns1:ProductionOptions>
<ns1:Type>ImageAndRecord</ns1:Type>
</ns1:Job>
</request>
</SubmitJob>
</soapenv:Body>
 
 
0
JonMnyAuthor Commented:
Ok I have done some more research, the problem is apache axis does not support multi-dimensional arrays which explains why it is not serializing properly. Does anyone know of a sample custom serializer for multidimesional arrays.
0
JonMnyAuthor Commented:
The answer is that axis2 still does not support multi-dimensional arrays.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.