Hi Pratibha,
There is already code in the UnmarshalHandler to deal with base64 and
byte[]'s. So if during unmarshalling it's not entering that block of
code then we need to figure out why.
I'll double check this later to see if I can duplicate the issue.
Thanks,
--Keith
Pratibha Gupta wrote:
>
> I posted this message y'day, but did not see it on the list. Hence
> posting it again. Apologise if the posting is duplicate.
>
> I ran into some problems while trying to unmarshal DOM --> Java Object.
>
> I had a complex type which had simple content that extended from
> base64Binary.
> i.e
> <complexType name="SomeType">
> <simpleContent>
> <extension base="base64Binary">
> </extension>
> </simpleContent>
> </complexType>
>
> <element name="SomeElement" type="SomeType"/>
>
> The class generated for SomeType had this method
> public void setContent(byte[] content)
> {
> this._content = content;
> } //-- void setContent(byte)
>
> When I tried to unmarshal a DOM to a Java object , I got a
> ClassCastException. The problem was that in
> castor/src/main/org/exolab/castor/xml/UnmarshalHandler.java, the
> content is converted to a String for ALL objects (even when the object
> is actually a byte[])
>
> Here is the code
> Object value = state.buffer.toString();
> if (isPrimitive(cdesc.getFieldType()))
> value = toPrimitiveObject(cdesc.getFieldType(), (String)value);
>
> Thus, setContent was called with a String parameter instead of a byte[],
> and that threw the class cast exception.
>
> IMHO, the code should read
> Object value = state.buffer.toString();
> if (isPrimitive(cdesc.getFieldType())) {
> value = toPrimitiveObject(cdesc.getFieldType(),
> (String)value);
> }
> /* special handling for byte arrays */
> else {
> Class fieldType = cdesc.getFieldType();
> if ( (fieldType.isArray()) &&
> (fieldType.getComponentType() == Byte.TYPE)) {
> value = ((String)value).getBytes();
> } // end of if ()
> } // end of else
> I put in these changes and the unmarshalling worked fine for
> my class. Has someone else faced the same problem? If yes, did u do
> anything different?
>
> Thanks,
> Pratibha
>
> -----------------------------------------------------------
> If you wish to unsubscribe from this mailing, send mail to
> [EMAIL PROTECTED] with a subject of:
> unsubscribe castor-dev
-----------------------------------------------------------
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
unsubscribe castor-dev