Hi Jason,

I ran your test case and was able to reproduce the problem, but I
haven't had a chance to dig into the source code and try and fix it yet.
I'll try to get to that later today after work hours.

Thanks,

--Keith

Jason Dillon wrote:
> 
> Any status on this problem?
> 
> --jason
> 
> > -----Original Message-----
> > From: Keith Visco [mailto:[EMAIL PROTECTED]
> > Sent: Friday, May 21, 2004 12:32 PM
> > To: [EMAIL PROTECTED]
> > Subject: Re: [castor-user] Problems marshalling class with an Object
> > fieldin
> >
> >
> >
> > Hi Jason,
> >
> > Thanks for resending the message as plain text.
> >
> > I'll try out your test case and see if I can see what's going on. I
> > agree that the missing wrapper element seems to be what's causing the
> > newer versions to struggle. Normally Castor treats collections as
> > "containers" meaning that they are not first class objects and only
> > their contents are marshalled. However, in the case of "Object
> > getObject()" a wrapper element is really needed for collections,
> > otherwise there will be no way of knowing how to rebuild the collection
> > upon unmarshalling.
> >
> > I'll see if I can track down where Castor is getting confused.
> >
> > --Keith
> >
> >
> > Jason Dillon wrote:
> > >
> > > A plain text version, in case that was causing anyone to ignore this
> > message
> > > ;-)
> > >
> > > --jason
> > >
> > > ________________________________________
> > > From: Jason Dillon [mailto:[EMAIL PROTECTED]
> > > Sent: Tuesday, May 18, 2004 2:56 PM
> > > To: [EMAIL PROTECTED]
> > > Cc: [EMAIL PROTECTED]
> > > Subject: [castor-user] Problems marshalling class with an Object field
> > in
> > > Castor v0.9.4. 3+
> > >
> > > Hi, I have been trying to track down a problem with later versions of
> > > Castor, where it is not marshalling a class with an Object field (that
> > > happens to be an ArrayList instance, but could be a String as well)...
> > but
> > > have had no luck and my brain is starting to hurt :-/
> > > First off, I am trying to use the _default_ marshalling/unmarshalling
> > > behavior _with-out_ a mapping file.
> > > Basically, I have a class like:
> > > <snip>
> > > // ...
> > > public class SimpleObject
> > > {
> > >     private Object value;
> > >
> > >     public SimpleObject()
> > >     {
> > >         super();
> > >     }
> > >
> > >     public SimpleObject(Object value)
> > >     {
> > >         setValue(value);
> > >     }
> > >
> > >     public void setValue(Object value)
> > >     {
> > >         this.value = value;
> > >     }
> > >
> > >     public Object getValue()
> > >     {
> > >         return value;
> > >     }
> > > }
> > > </snip>
> > > So, value could be a String or a List or really anything...
> > > And a testcase like:
> > > <snip>
> > > // ...
> > > public class CastorNoMappingTestCase
> > >     extends TestCase
> > > {
> > >     protected void log(String msg)
> > >     {
> > >         System.err.println(msg);
> > >     }
> > >
> > >     protected Marshaller getMarshaller(final Writer writer) throws
> > Exception
> > >     {
> > >         Marshaller marshaller = new Marshaller(writer);
> > >         // marshaller.setMarshalExtendedType(true);
> > >         // marshaller.setSuppressXSIType(false);
> > >         marshaller.setNamespaceMapping("xsi",
> > > "http://www.w3.org/2001/XMLSchema-instance";);
> > >         return marshaller;
> > >     }
> > >
> > >     protected Object chew(final Object input, final Class type) throws
> > > Exception
> > >     {
> > >         StringWriter writer = new StringWriter();
> > >         Marshaller marshaller = getMarshaller(writer);
> > >         marshaller.marshal(input);
> > >
> > >         writer.flush();
> > >         String xml = writer.toString();
> > >         assertNotNull(xml);
> > >         log("XML: " + xml);
> > >
> > >         Reader reader = new StringReader(xml);
> > >         Unmarshaller unmarshaller = new Unmarshaller(type);
> > >         Object target = unmarshaller.unmarshal(reader);
> > >         assertNotNull(target);
> > >
> > >         return target;
> > >     }
> > >
> > >     protected Object chew(final Object input) throws Exception
> > >     {
> > >         return chew(input, input.getClass());
> > >     }
> > >
> > >     public void testSimpleObject_ArrayList_chew() throws Exception
> > >     {
> > >         List list = new ArrayList();
> > >         list.add("a");
> > >         list.add("b");
> > >
> > >         SimpleObject obj1 = new SimpleObject(list);
> > >         Object obj2 = chew(obj1);
> > >
> > >         SimpleObject obj3 = (SimpleObject)obj2;
> > >         assertEquals(obj1.getValue(), obj3.getValue());
> > >     }
> > >
> > >     public void testSimpleObject_ArrayList2_chew() throws Exception
> > >     {
> > >         List list1 = new ArrayList();
> > >         List list2 = new ArrayList();
> > >         list2.add("c");
> > >         list2.add("d");
> > >         list1.add(list2);
> > >
> > >         SimpleObject obj1 = new SimpleObject(list1);
> > >         Object obj2 = chew(obj1);
> > >
> > >         SimpleObject obj3 = (SimpleObject)obj2;
> > >         assertEquals(obj1.getValue(), obj3.getValue());
> > >     }
> > > }
> > > </snip>
> > > Castor version 0.9.4.2 (and previous, at least until 0.9.3.21) will
> > marshall
> > > and unmarshall this class with no errors.
> > > Castor 0.9.4.2 (from http://www.ibiblio.org/maven/castor/jars) produces
> > > this:
> > > <snip>
> > > Tests run: 2, Failures: 0, Errors: 0, Time elapsed: 0.562 sec
> > > ------------- Standard Error -----------------
> > > XML: <?xml version="1.0" encoding="UTF-8"?>
> > > <simple-object xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
> > > xmlns="">
> > >     <value xsi:type="java:java.util.ArrayList">
> > >         <string xsi:type="java:java.lang.String">a</string>
> > >         <string xsi:type="java:java.lang.String">b</string>
> > >     </value>
> > > </simple-object>
> > > XML: <?xml version="1.0" encoding="UTF-8"?>
> > > <simple-object xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
> > > xmlns="">
> > >     <value xsi:type="java:java.util.ArrayList">
> > >         <null xsi:type="java:java.util.ArrayList">
> > >             <string xsi:type="java:java.lang.String">c</string>
> > >             <string xsi:type="java:java.lang.String">d</string>
> > >         </null>
> > >     </value>
> > > </simple-object>
> > > ------------- ---------------- ---------------
> > > </snip>
> > > But Castor version 0.9.4.3+ fail.  Specifically 0.9.4.3 and 0.9.5.3.
> > > Castor 0.9.4.3 (from http://www.ibiblio.org/maven/castor/jars) produces
> > > this:
> > > <snip>
> > > Tests run: 2, Failures: 1, Errors: 1, Time elapsed: 0.688 sec
> > > ------------- Standard Error -----------------
> > > XML: <?xml version="1.0" encoding="UTF-8"?>
> > > <simple-object xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";>
> > >     <value xsi:type="java:java.lang.String">a</value>
> > >     <value xsi:type="java:java.lang.String">b</value>
> > > </simple-object>
> > > XML: <?xml version="1.0" encoding="UTF-8"?>
> > > <simple-object xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";>
> > >     <value xsi:type="java:java.util.ArrayList">
> > >         <string xsi:type="java:java.lang.String">c</string>
> > >         <string xsi:type="java:java.lang.String">d</string>
> > >     </value>
> > > </simple-object>
> > > ------------- ---------------- ---------------
> > > Testcase: testSimpleObject_ArrayList_chew(CastorNoMappingTestCase):
> > > Caused an ERROR
> > > element "value" occurs more than once. (XMLFieldDesciptor: value AS
> > value)
> > > ValidationException: element "value" occurs more than once.
> > > (XMLFieldDesciptor: value AS value)
> > >         at
> > >
> > org.exolab.castor.xml.UnmarshalHandler.endElement(UnmarshalHandler.java:73
> > 0)
> > >         at
> > org.apache.xerces.parsers.AbstractSAXParser.endElement(Unknown
> > > Source)
> > >         at
> > >
> > org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanEndElement(Unkno
> > wn
> > > Source)
> > >         at
> > >
> > org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispa
> > tc
> > > her.dispatch(Unknown Source)
> > >         at
> > >
> > org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown
> > > Source)
> > >         at org.apache.xerces.parsers.XML11Configuration.parse(Unknown
> > > Source)
> > >         at org.apache.xerces.parsers.XML11Configuration.parse(Unknown
> > > Source)
> > >         at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
> > >         at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown
> > Source)
> > >         at
> > > org.exolab.castor.xml.Unmarshaller.unmarshal(Unmarshaller.java:555)
> > >         at
> > > org.exolab.castor.xml.Unmarshaller.unmarshal(Unmarshaller.java:487)
> > >         at CastorNoMappingTestCase.chew(CastorNoMappingTestCase.java:52)
> > >         at CastorNoMappingTestCase.chew(CastorNoMappingTestCase.java:60)
> > >         at
> > >
> > CastorNoMappingTestCase.testSimpleObject_ArrayList_chew(CastorNoMappingTes
> > tC
> > > ase.java:70)
> > > Testcase: testSimpleObject_ArrayList2_chew(CastorNoMappingTestCase):
> > > FAILED
> > > expected:<[[c, d]]> but was:<[c, d]>
> > > junit.framework.AssertionFailedError: expected:<[[c, d]]> but was:<[c,
> > d]>
> > >         at
> > >
> > CastorNoMappingTestCase.testSimpleObject_ArrayList2_chew(CastorNoMappingTe
> > st
> > > Case.java:88)
> > > </snip>
> > > And Castor 0.9.5.3 (from http://www.ibiblio.org/maven/castor/jars)
> > produces
> > > output
> > > very similar.  Specifically the output 'XML:' is identical.
> > >  * * *
> > > Comparing the two outputs it appears as if the first level container
> > element
> > > is eaten somewhere, which is then causing some duplicate elements to get
> > > written.  The second stack trace shows the same thing, where I was
> > expecting
> > > a List within a List, but only got back a single List.
> > > I have searched the net for the past few days, sifted through the
> > mailing
> > > lists. I did find a few people seeing this particular
> > ValidationException,
> > > but no solutions.
> > > Anyone have a clue?  Looks like something changes between Castor 0.9.4.2
> > and
> > > 0.9.4.3 which broke Castors ability to marshal and unmarshall objects
> > like
> > > SimpleObject with no mapping.  BTW, the no mapping part is critical, as
> > the
> > > system I am trying to fix this for relies upon the fact that Castor will
> > do
> > > the right thing with an object with out a mapping.
> > > Also, a side note about XMLNaming (rather DefaultNaming), it does not
> > > properly handle nested classes (classes which have a '$' in the class
> > > name).  Not really a big deal from a production level, but a pain in the
> > ass
> > > when trying to write test cases for castor using nested mock object
> > classes.
> > > Unfortunally 0.9.4.2 does not pay attention to the
> > > 'org.exolab.castor.xml.naming' in my castor.properties file, so I will
> > have
> > > to live with out nested class (un)marshalling for now.
> > > Finally, just incase anyone asks here is the castor.properites which is
> > on
> > > my  classpath:
> > > <snip>
> > > # ...
> > > org.exolab.castor.parser=org.apache.xerces.parsers.SAXParser
> > > org.exolab.castor.serializer=org.apache.xml.serialize.XMLSerializer
> > > org.exolab.castor.regexp=org.exolab.castor.util.JakartaRegExpEvaluator
> > > org.exolab.castor.indent=true
> > > org.exolab.castor.parser.validation=false
> > > org.exolab.castor.parser.namespaces=false
> > > org.exolab.castor.marshalling.validation=true
> > > org.exolab.castor.xml.naming=XMLNamingImpl
> > > org.exolab.castor.debug=false
> > > org.exolab.castor.mapping.collections=\
> > >   org.exolab.castor.mapping.loader.J1CollectionHandlers,\
> > >   org.exolab.castor.mapping.loader.J2CollectionHandlers
> > > org.exolab.castor.builder.type.j2=\
> > >   org.exolab.castor.builder.FieldInfoFactoryJ2
> > > org.exolab.castor.builder.type.j1=\
> > >   org.exolab.castor.builder.FieldInfoFactory
> > > org.exolab.castor.builder.type.odmg=\
> > >   org.exolab.castor.builder.FieldInfoFactoryODMG30
> > > </snip>
> > >  * * *
> > > If you have ANY idea what is going on here... any idea... please drop
> > some
> > > knowledge.
> > > Thanks,
> > > --jason
> > >
> > >   ----------------------------------------------------------------------
> > --
> > >
> > >    footerName: footer
> > >          Type: Plain Text (text/plain)
> > >
> > >   ----------------------------------------------------------------------
> > --
> > > -----------------------------------------------------------
> > > If you wish to unsubscribe from this mailing, send mail to
> > > [EMAIL PROTECTED] with a subject of:
> > >         unsubscribe castor-user
> >
> >
> >
> > -----------------------------------------------------------
> > If you wish to unsubscribe from this mailing, send mail to
> > [EMAIL PROTECTED] with a subject of:
> >         unsubscribe castor-user
> 
> -----------------------------------------------------------
> If you wish to unsubscribe from this mailing, send mail to
> [EMAIL PROTECTED] with a subject of:
>         unsubscribe castor-user



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

Reply via email to