?
Solved

Java Array string

Posted on 2009-07-03
15
Medium Priority
?
824 Views
Last Modified: 2012-06-22
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

0
Comment
Question by:JonMny
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 7
15 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 24773933
>>I am creating a multi dimensional array in java and assigning it to that value

How? Please post code
0
 
LVL 9

Author Comment

by:JonMny
ID: 24774677
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
 
LVL 86

Expert Comment

by:CEHJ
ID: 24774742
>>mergeData

is not shown in your code - where do you initialize it?
0
Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

 
LVL 86

Expert Comment

by:CEHJ
ID: 24774760
>>values[0] = "Row1Value1";

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


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

Open in new window

0
 
LVL 9

Author Comment

by:JonMny
ID: 24774805
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
 
LVL 86

Expert Comment

by:CEHJ
ID: 24774817
You may find, as is most the case where serialization is  involved, only the no-arg ctor gets called
0
 
LVL 9

Author Comment

by:JonMny
ID: 24775018
I am calling the no arg constructors.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 24776129
Can you post the actual error message you're getting?
0
 
LVL 9

Author Comment

by:JonMny
ID: 24785134
there is not an error generated, the problem is the resulting soap message has a "" instead of the values from the array
0
 
LVL 9

Author Comment

by:JonMny
ID: 24785789
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
 
LVL 86

Expert Comment

by:CEHJ
ID: 24785873
MergeData has not been deserialized properly. Probably for the reasons i already gave you
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 24785894
Sorry - ignore that last comment
0
 
LVL 9

Author Comment

by:JonMny
ID: 24786324
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
 
LVL 9

Author Comment

by:JonMny
ID: 24840027
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
 
LVL 9

Accepted Solution

by:
JonMny earned 0 total points
ID: 24981668
The answer is that axis2 still does not support multi-dimensional arrays.
0

Featured Post

WordPress Tutorial 3: Plugins, Themes, and Widgets

The three most common changes you will make to your website involve the look (themes), the functionality (plugins), and modular elements (widgets).

In this article we will briefly define each again, and give you directions on how to install them.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

These instructions are based on installing Owncloud on your new raspberry pi connected with a usb HDD. What do you need Part A? A Raspberry Pi, model B. A boot SD card for the Raspberry Pi. A usb HDD An Ethernet cable to connect to the lo…
The task of choosing a web design company to build a website for your business should never be taken in a light manner. Provided the fact that your website will act as a representative to your business and will be responsible for imposing an online …
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses
Course of the Month14 days, 7 hours left to enroll

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question