Hi Bikash,
I haven't had a chance to look into this, but apparently the
introspector is smarter than the mapping loader, which is not
surprising. :-)
We will be doing a full overhaul of the Mapping API soon, but for now,
perhaps you can use a Mix of both mapping and introspection.
If you can, specify all the fields...except the field that uses "char"
and then simply enable auto-complete.
<class name="..." auto-complete="true">
<!-- specify all fields except ones that you wish to be introspected
-->
</class>
For this to work you'll need to be using the CVS version of Castor.
Thanks,
--Keith
Bikash Behera wrote:
>
> Hi,
>
> We are using Castor XML for marshaling / unmarshaling java objects.
> We provide map files to specify xml tags to use.
>
> I am having problem unmarshaling fields with simple types "char" and "byte".
>
> In the map file I specify the type of the field as "char" and "byte"
> respectively.
> But it blows with the following exception:
> java.lang.IllegalArgumentException: Type conversion error: could not set
> value of value(java.lang.Character)
> with value of type java.lang.String
>
> The marshaling part does not seem to have any problem only unmarshaling
> fails with the specified mapping file.
> The marshaling/unmarshaling work properly if I don't specify any mapping
> file (but I need to use mapping files).
> Did I miss anything here. I even tried specifying "java.lang.Character.TYPE"
> as the type instead of "char".
> I still does not work. Please let me know what should I do.
>
> Attached herewith are the files I use.
>
> Thanks,
> Bikash.
>
> // JAVA SOURCE FILE
> public class Temp
> {
> protected char value;
>
> public Temp()
> {
> }
>
> public char getValue()
> {
> return value;
> }
>
> public void setValue(char c)
> {
> this.value = c;
> }
>
> public String toString()
> {
> return "Value = " + value;
> }
> }
>
> // MAP FILE
> <?xml version="1.0"?>
> <!DOCTYPE mapping PUBLIC "-//EXOLAB/Castor Object Mapping DTD Version
> 1.0//EN"
> "http://Castor.exolab.org/mapping.dtd">
>
> <mapping>
> <class name="Temp">
> <map-to xml="Data"/>
>
> <field name="value"
> type="char">
> <bind-xml name="val" node="element"/>
> </field>
> </class>
> </mapping>
>
> // TEST FILE
>
> import java.io.FileReader;
> import java.io.FileWriter;
> import org.exolab.castor.mapping.Mapping;
> import org.exolab.castor.xml.Marshaller;
> import org.exolab.castor.xml.Unmarshaller;
>
> public class Test
> {
> public static void main(String[] args)
> {
> try
> {
> Temp temp1 = new Temp();
> temp1.setValue('x');
>
> System.out.println("Before : " + temp1);
>
> FileWriter writer = new FileWriter("\\temp\\temp.xml");
>
> Marshaller marshaller = new Marshaller(writer);
>
> Mapping mapping = new Mapping();
> mapping.loadMapping("\\temp\\mapping.xml");
> marshaller.setMapping(mapping);
>
> marshaller.marshal(temp1);
>
> FileReader reader = new FileReader("\\temp\\temp.xml");
>
> Unmarshaller unmarshaller = new Unmarshaller(Temp.class);
> unmarshaller.setMapping(mapping);
>
> Temp temp2 = (Temp) unmarshaller.unmarshal(reader);
>
> System.out.println("After : " + temp2);
> }
> catch(Exception ex)
> {
> ex.printStackTrace();
> }
> }
> }
>
> // THE EXCEPTION
> org.xml.sax.SAXException: unable to add 'val' to <Data> due to the following
> exception:
> >>>--- Begin Exception ---<<<
> java.lang.IllegalArgumentException: Type conversion error: could not set
> value of value(java.lang.Character) with value of type java.lang.String
> at
> org.exolab.castor.mapping.loader.FieldHandlerImpl.setValue(FieldHandlerImpl.
> java:460) at
> org.exolab.castor.xml.UnmarshalHandler.endElement(UnmarshalHandler.java:522)
> at org.apache.xerces.parsers.SAXParser.endElement(SAXParser.java:1392) at
> org.apache.xerces.validators.common.XMLValidator.callEndElement(XMLValidator
> .java:1456) at
> org.apache.xerces.framework.XMLDocumentScanner$ContentDispatcher.dispatch(XM
> LDocumentScanner.java:1205) at
> org.apache.xerces.framework.XMLDocumentScanner.parseSome(XMLDocumentScanner.
> java:381) at
> org.apache.xerces.framework.XMLParser.parse(XMLParser.java:1081) at
> org.exolab.castor.xml.Unmarshaller.unmarshal(Unmarshaller.java:338) at
> org.exolab.castor.xml.Unmarshaller.unmarshal(Unmarshaller.java:270) at
> Test.main(Test.java:34) >>>---- End Exception ----<<<
> at
> org.exolab.castor.xml.UnmarshalHandler.endElement(UnmarshalHandler.java:552)
> at org.apache.xerces.parsers.SAXParser.endElement(SAXParser.java:1392) at
> org.apache.xerces.validators.common.XMLValidator.callEndElement(XMLValidator
> .java:1456) at
> org.apache.xerces.framework.XMLDocumentScanner$ContentDispatcher.dispatch(XM
> LDocumentScanner.java:1205) at
> org.apache.xerces.framework.XMLDocumentScanner.parseSome(XMLDocumentScanner.
> java:381) at
> org.apache.xerces.framework.XMLParser.parse(XMLParser.java:1081) at
> org.exolab.castor.xml.Unmarshaller.unmarshal(Unmarshaller.java:338) at
> org.exolab.castor.xml.Unmarshaller.unmarshal(Unmarshaller.java:270) at
> Test.main(Test.java:34)
-----------------------------------------------------------
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
unsubscribe castor-dev