Details
-
Type:
Bug
-
Status:
Open
-
Priority:
Major
-
Resolution: Unresolved
-
Affects Version/s: 0.9.7
-
Fix Version/s: None
-
Component/s: XML code generator
-
Labels:None
-
Number of attachments :
Description
When using a binding file to specify that certain primitive fields should be wrapped (rather than using the Castor properties file to specify that ALL primitives should be wrapped) the 'descriptor' class will still contain a call to the field's delete method and therefore won't compile because there won't be such a delete method in the actual binding class ('has' and 'delete' methods are omitted when primitive wrapper classes are used).
Example:
In the following example the FooDto type has a barId field that references a BarDto by id. A Foo doesn't always have an associated Bar, so the barId element is defined as minOccurs="0" in the XSD.
Snippet from XSD:
<xs:complexType name="FooDto">
<xs:sequence>
<xs:element name="id" type="xs:int"/>
<xs:element name="name" type="xs:string"/>
<xs:element name="barId" type="xs:int" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
Snippet from the binding file that causes the problem:
<complexTypeBinding name="FooDto">
<java-class name="FooDto"/>
<elementBinding name="barId">
<member wrapper="true"/>
</elementBinding>
</complexTypeBinding>
Suggested Fix
-------------
Line 519 in org\exolab\castor\builder\DescriptorSourceFactory.java:
if (xsType.isPrimitive() && !_config.usePrimitiveWrapper()) {
Should be:
if (xsType.getJType().isPrimitive() && !_config.usePrimitiveWrapper()) {
I suspect this could now be simplified to:
if (xsType.getJType().isPrimitive()) {
I've tested this and it works OK for my XSD and binding file. (Should XSType.isPrimitive() be deprecated in favour of
XSType.getJType().isPrimitive()? Or should it delegate to JType.isPrimitive()?)
Can you please attach a complete (though minimal) XML schema and the associated binding file ? And if you are using any non-default builder properties, i#d like to see these as well ....