Hello,
I'm working on CASTOR-2119 issue and encountered a problem which I'm
not sure how to solve... so I ask you to help me finding a solution.
The problem is about xsi:type and when this attribute should be added
to an element.
The logic for this question can be found in class:
org.exolab.castor.xml.Marshaller in method:
private void marshal
(Object object,
XMLFieldDescriptor descriptor,
ContentHandler handler,
final MarshalState mstate)
throws MarshalException, ValidationException
If xsi:type is used or not is determined by many facts and the one I
want to discuss can be described as:
When no descriptor is known or the descriptor is for a different class
(which is assigneable of course) then add an xsi:type attribute.
There is also a test case which verifies this behaviour: marshalling/xsi-type.
So far things sound fine... lets jump deeper into it.
Test case 'marshalling/xsi-type' basically performs three steps:
1) unmarshal an input file
2) marshal, the result of the unmarshal step, into a new file
3) compare the input file and the file from marshalling
In castor HEAD this works fine:
1) Unmarshal encounters a field 'foo'; needs a class for it;
introspects 'Foo'; fills Foo.
2) Then marshaller has a class Foo to marshal; has no descriptor for
it (creates xsi:type attribute); introspects for descriptor; creates
XML
3) the two files are equal
In my patch I introduce an enhancement into Castor! Descriptor
informations are no longer thrown away, they are reused!!
In castor-2119 the processing is:
1) Unmarshal encounters a field 'foo'; needs a class for it;
introspects 'Foo'; fills Foo.
2) Then marshaller has a class Foo to marshal; it still has the
descriptor of Foo from the unmarshaller -> no xsi:type!; it creates
the XML without xsi:type for Foo
3) BANG - Gold file and file creaed by Marshaller are NOT equal
A quick solution will be to throw away all known descriptors before
entering Marshaller. But this is dirty!
Also Castor will produce a different output when:
1) Call marshalling 'cold' so it has to introspect every class.
2) Create an XMLClassDescriptorResolver (CDR) instance; add all
classes to the CDR; create a Marshaller; put the CRD into the
Marshaller; start marshalling with this Marshaller instance
After all this introduction, my question is:
When should Castor put 'xsi:type' to an element? I think this rule
'when no class descriptor is known' should be 'for every introspected
class descriptor' shouldn't it be?
Looking forward to your feedback.
Regards
Joachim
---------------------------------------------------------------------
To unsubscribe from this list please visit:
http://xircles.codehaus.org/manage_email