I encountered problems with Marshalling Framework when trying to
marshall/unmarshall byte[] content.
It looks like Marshaller prints out the byte array with toString()
method. Because of that the unmarshalling throws an ClassCastException
when trying to unmarshall base64binary type.
Source code:
try
{
PrintWriter stdout = new PrintWriter(System.out);
FileWriter file = new FileWriter("test.txt");
byte[] data = "{1,2};
Test msg = new Test();
msg.setFoo(data);
msg.marshal(stdout);
msg.marshal(file);
}
catch(Exception e)
{
System.out.println(e);
}
try
{
FileReader file = new FileReader("test.txt");
Test msg = Test.unmarshal(file);
PrintWriter stdout = new PrintWriter(System.out);
msg.marshal(stdout);
}
catch(Exception e)
{
System.out.println(e);
}
Schema:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="test">
<xs:complexType>
<xs:attribute name="foo" type="xs:base64Binary"/>
</xs:complexType>
</xs:element>
</xs:schema>
Console output:
<?xml version="1.0" encoding="UTF-8"?>
<test foo="[B@fa3ac1"/>
org.xml.sax.SAXException: unable to add attribute "foo" to
'fi.tut.pe.minifactory.common.message.Test' due to the following error:
java.lang.IllegalStateException: java.lang.ClassCastException:
java.lang.String{file: [not available]; line: 2; column: 31}
There has been some discussion about the problem and it is noted that
the problem is already fixed in the latest cvs version,
but I am using the latest version. Dated 8. October, 2002.
Am I doing something wrong or does the problem still exists?
-Miika Parvio
Miika Parvio
TTKK/TTEK Mob: +358 -44-3550181
PL589
33101 Tampere
Finland
