Any news on the status of this bug?
--jason
On May 21, 2004, at 1:31 PM, Keith Visco wrote:
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:message
A plain text version, in case that was causing anyone to ignore thisin;-)
--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 fieldbutCastor 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)...Exceptionhave 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) throwsmarshall{ 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) willproducesand unmarshall this class with no errors. Castor 0.9.4.2 (from http://www.ibiblio.org/maven/castor/jars)producesthis: <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)value)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 ASorg.exolab.castor.xml.UnmarshalHandler.endElement(UnmarshalHandler.java :ValidationException: element "value" occurs more than once. (XMLFieldDesciptor: value AS value) at
730)atorg.apache.xerces.parsers.AbstractSAXParser.endElement(Unknownorg.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanEndElement(Un kSource) at
nownorg.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDi sSource) at
patcorg.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unkn oher.dispatch(Unknown Source) at
wnSource)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(UnknownCastorNoMappingTestCase.chew(CastorNoMappingTestCase.java:52)at org.exolab.castor.xml.Unmarshaller.unmarshal(Unmarshaller.java:555) at org.exolab.castor.xml.Unmarshaller.unmarshal(Unmarshaller.java:487) atatCastorNoMappingTestCase.chew(CastorNoMappingTestCase.java:60)CastorNoMappingTestCase.testSimpleObject_ArrayList_chew(CastorNoMapping Tat
estCd]>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,CastorNoMappingTestCase.testSimpleObject_ArrayList2_chew(CastorNoMappin gat
TestproducesCase.java:88) </snip> And Castor 0.9.5.3 (from http://www.ibiblio.org/maven/castor/jars)elementoutput very similar. Specifically the output 'XML:' is identical. * * * Comparing the two outputs it appears as if the first level containeris eaten somewhere, which is then causing some duplicate elements togetwritten. The second stack trace shows the same thing, where I wasexpectingmailinga List within a List, but only got back a single List. I have searched the net for the past few days, sifted through thelists. I did find a few people seeing this particularValidationException,0.9.4.2 andbut no solutions. Anyone have a clue? Looks like something changes between Castor0.9.4.3 which broke Castors ability to marshal and unmarshall objectslikeSimpleObject with no mapping. BTW, the no mapping part is critical,as thesystem I am trying to fix this for relies upon the fact that Castorwill dothe assthe 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 inwhen trying to write test cases for castor using nested mock objectclasses.haveUnfortunally 0.9.4.2 does not pay attention to the 'org.exolab.castor.xml.naming' in my castor.properties file, so I willis onto live with out nested class (un)marshalling for now. Finally, just incase anyone asks here is the castor.properites whichsomemy 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----------------------------------------------------------------------- -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
PGP.sig
Description: PGP signature
-----------------------------------------------------------
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
unsubscribe castor-user
