Hello there again!

I still have the problem unmarshalling arrays of java interfaces. I post
this message again, maybe it was lost somewhere. I just downloaded the
lastest CVS version of Castor but the problem still exists. Is this a bug?
Please look at the following simple example:

Class1:

public class ArrayTest implements ArrayTestInt {
      private String[] strings = null;
}

Class 2:

public class ArrayTest2 implements ArrayTestInt {
      private String[] strings = null;
}

Class3:

public class ArrayTest3 {

      private ArrayTestInt[] tests;

      public ArrayTestInt[] getTests() {
            return tests;
      }

      public void setTests(ArrayTestInt[] tests) {
            this.tests = tests;
      }
}

Interface1:

public interface ArrayTestInt {
}

TesterClass:

import java.io.Serializable;

public class ArrayTester {

      public static void main(String[] args) {
            ArrayTest test = new ArrayTest();
            ArrayTest2 test2 = new ArrayTest2();

            ArrayTest3 test3 = new ArrayTest3();

            test3.setTests(new ArrayTestInt[] { test, test2 });

            ByteArrayOutputStream stream = new ByteArrayOutputStream();
            PrintWriter writer = new PrintWriter(stream);

            try {
                  Marshaller.marshal(test3, writer);
                  System.out.println(stream.toString());
            } catch(Exception e) {
            }

            StringReader reader = new StringReader(stream.toString());
            try {
                  ArrayTest3 test4 = (ArrayTest3)
Unmarshaller.unmarshal(ArrayTest3.class, reader);
            } catch(Exception e) {
            }
      }
}

I convert an object with an array of objects of type ArrayTestInt into xml
and get the following output:

<?xml version="1.0"?>
<array-test3><tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
xsi:type="java:ArrayTest"/><tests xmlns:xsi="
http://www.w3.org/2001/XMLSchema-instance"; xsi:type="java:ArrayTest2
"/></array-test3>

When I convert this back into an object I get the following exception:

org.xml.sax.SAXException: unable to add 'tests' to <array-test3> due to the
following exception:
>>>--- Begin Exception ---<<<
java.lang.IllegalArgumentException: array element type mismatch
      at java.lang.reflect.Array.set(Native Method)
      at
org.exolab.castor.mapping.loader.J1CollectionHandlers$1.add(J1CollectionHandlers.java:109)
      at
org.exolab.castor.mapping.loader.FieldHandlerImpl.setValue(FieldHandlerImpl.java:513)
      at
org.exolab.castor.xml.UnmarshalHandler.endElement(UnmarshalHandler.java:526)
      at
org.apache.xerces.parsers.SAXParser.endElement(SAXParser.java:1392)
      at
org.apache.xerces.validators.common.XMLValidator.callEndElement(XMLValidator.java:1180)
      at
org.apache.xerces.framework.XMLDocumentScanner.scanElement(XMLDocumentScanner.java:1861)
      at
org.apache.xerces.framework.XMLDocumentScanner$ContentDispatcher.dispatch(XMLDocumentScanner.java:1234)
      at
org.apache.xerces.framework.XMLDocumentScanner.parseSome(XMLDocumentScanner.java:381)
      at org.apache.xerces.framework.XMLParser.parse(XMLParser.java:952)
      at
org.exolab.castor.xml.Unmarshaller.unmarshal(Unmarshaller.java:338)
      at
org.exolab.castor.xml.Unmarshaller.unmarshal(Unmarshaller.java:270)
      at
org.exolab.castor.xml.Unmarshaller.unmarshal(Unmarshaller.java:391)
      at XMLUtilities.convertXMLToObject(XMLUtilities.java:96)
      at ArrayTester.main(ArrayTester.java:16)
>>>---- End Exception ----<<<

      at
org.exolab.castor.xml.UnmarshalHandler.endElement(UnmarshalHandler.java:557)
      at
org.apache.xerces.parsers.SAXParser.endElement(SAXParser.java:1392)
      at
org.apache.xerces.validators.common.XMLValidator.callEndElement(XMLValidator.java:1180)
      at
org.apache.xerces.framework.XMLDocumentScanner.scanElement(XMLDocumentScanner.java:1861)
      at
org.apache.xerces.framework.XMLDocumentScanner$ContentDispatcher.dispatch(XMLDocumentScanner.java:1234)
      at
org.apache.xerces.framework.XMLDocumentScanner.parseSome(XMLDocumentScanner.java:381)
      at org.apache.xerces.framework.XMLParser.parse(XMLParser.java:952)
      at
org.exolab.castor.xml.Unmarshaller.unmarshal(Unmarshaller.java:338)null

      at
org.exolab.castor.xml.Unmarshaller.unmarshal(Unmarshaller.java:270)
      at
org.exolab.castor.xml.Unmarshaller.unmarshal(Unmarshaller.java:391)
      at XMLUtilities.convertXMLToObject(XMLUtilities.java:96)
      at ArrayTester.main(ArrayTester.java:16)

I don't want to use a mapping file because my real objects are a bit
complicated. Could you tell me what I should do to solve my problem?
I searched the mail archive and found a similiar problem posted in february
2001 but I didn't find any answer. Please help!

Thanks in advance

stefan

----------------------------------------------------------- 
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
        unsubscribe castor-dev

Reply via email to