I have run the test with the source of the trunck in eclipse and got the
same error so if it is a bug I think it is not corrected.
I have created a bug (*CASTOR-2181
<http://jira.codehaus.org/browse/CASTOR-2181>).*
/Sylvain/
----- Message d'origine ----
De : Werner Guttmann <[EMAIL PROTECTED]>
À : [email protected]
Envoyé le : Mardi, 2 Octobre 2007, 11h25mn 38s
Objet : Re: [castor-user] Re : [castor-user] Tr : Tr : unmarsalling xml
with xsi:type
Sylvain,
I guess this relates to one of the existing Jira issues, correct. Of so,
can you please make this (new) information available as part of the
existing Jira issue. If not, please feel free to create a new one.
Regards
Werner
Sylvain Lemasson wrote:
> I have make a test with only one schema and it works fine. The
> unmarshalling and the marshalling does not rase any error.
>
> So the issue arise when two schemas are used.
>
> /Sylvain/
>
>
> ----- Message d'origine ----
> De : Sylvain Lemasson <[EMAIL PROTECTED]>
> À : [email protected]
> Envoyé le : Dimanche, 16 Septembre 2007, 13h20mn 28s
> Objet : [castor-user] Tr : Tr : unmarsalling xml with xsi:type
>
>
> Hello,
> I have the following xsd files:
>
> parent.xsd
> <?xml version="1.0" encoding="UTF-8"?>
> <schema
> xmlns="http://www.w3.org/2001/XMLSchema"
<http://www.w3.org/2001/XMLSchema%22>;
> targetNamespace="http://www.example.org/parent"
<http://www.example.org/parent%22>;
> xmlns:tns="http://www.example.org/parent"
<http://www.example.org/parent%22>;>
>
> <complexType name="vehicle" abstract="true">
> <sequence>
> <element name="name" minOccurs="1" maxOccurs="1"></element>
> </sequence>
> </complexType>
>
> <complexType name="travel">
> <sequence>
> <element name="myvehicle" type="tns:vehicle">
>
> </element>
> </sequence>
> </complexType>
>
> <element name="root">
> <complexType>
> <sequence>
> <element name="travel" type="tns:travel" minOccurs="1"
> maxOccurs="1"></element>
> </sequence>
> </complexType>
> </element>
> </schema>
>
> child.xsd
> <?xml version="1.0" encoding="UTF-8"?>
> <schema
> xmlns="http://www.w3.org/2001/XMLSchema"
<http://www.w3.org/2001/XMLSchema%22>;
> targetNamespace="http://www.example.org/child"
<http://www.example.org/child%22>;
> xmlns:tns="http://www.example.org/child"
<http://www.example.org/child%22>;
> xmlns:parent="http://www.example.org/parent"
<http://www.example.org/parent%22>;>
>
>
>
> <complexType name="car" abstract="false">
> <complexContent>
> <extension base="parent:vehicle">
> <sequence>
> <element name="color" type="string"></element>
> </sequence>
> </extension>
> </complexContent>
> </complexType>
> </schema>
>
> Using the attribute org.exolab.castor.builder.javaclassmapping=type the
> generator create four classes: Root,Car,Vegicle,Travel.
> The marshalling works fine, but I always got unmarshalling error using
> "unable to find FieldDescriptor for 'myvehicle' in ClassDescriptor of
> travel" even when using a mapping file.
> I try first with Unmarshaller.unmarshal(Root.class, reader);
> Then with
> Mapping mapping = new Mapping();
> mapping.loadMapping("mapping.xml");
> Unmarshaller unmarshaller = new Unmarshaller(mapping);
>
> where mapping.xml contains:
> <?xml version="1.0" encoding="UTF-8"?>
> <mapping>
> <class name="com.example.castor.type.Root">
> <map-to xml="root"/>
> <field name="travel"
> type="com.example.castor.type.Travel"
> direct="false">
> <bind-xml name="travel" node="element"/>
> </field>
> </class>
>
> <class name="com.example.castor.type.Travel">
> <map-to xml="travel"/>
> <field name="myvehicle"
> type="com.example.castor.type.Vehicle"
> direct="false">
> <bind-xml node="element" auto-naming="deriveByClass"/>
> </field>
> </class>
>
> <class name="com.example.castor.type.Car">
> <map-to xml="car"/>
> </class>
>
> <class name="com.example.castor.type.Vehicle">
> <map-to xml="vehicle"/>
> </class>
> </mapping>
>
> May be something is wrong in the mapping file, I have set it base on the
> example in the documentation "XML Mapping, xsi-type".
>
> public static void main(String[] args) {
> try {
>
> StringWriter writer = new StringWriter();
>
> com.example.castor.type.Car car = new
> com.example.castor.type.Car();
> car.setColor("blue");
> car.setName("titine");
> Travel travel = new Travel();
> travel.setMyvehicle(car);
> Root root = new Root();
> root.setTravel(travel);
> root.marshal(writer);
>
> String xml = writer.getBuffer().toString();
> System.out.println(xml);
> StringReader reader = new StringReader(xml);
>
> Mapping mapping = new Mapping();
> mapping.loadMapping("mapping.xml");
> Unmarshaller unmarshaller = new Unmarshaller(mapping);
> //Unmarshaller.unmarshal(Root.class, reader);
> root = (Root)unmarshaller.unmarshal(reader);
> } catch (Exception e) {
> e.printStackTrace();
> }
> }
>
> Please advice.
> Sylvain
>
>
> ------------------------------------------------------------------------
> Ne gardez plus qu'une seule adresse mail ! Copiez vos mails
> <http://www.trueswitch.com/yahoo-fr/> vers Yahoo! Mail
>
>
> ------------------------------------------------------------------------
> Ne gardez plus qu'une seule adresse mail ! Copiez vos mails
> <http://www.trueswitch.com/yahoo-fr/> vers Yahoo! Mail
---------------------------------------------------------------------
To unsubscribe from this list please visit:
http://xircles.codehaus.org/manage_email
------------------------------------------------------------------------
Ne gardez plus qu'une seule adresse mail ! Copiez vos mails
<http://www.trueswitch.com/yahoo-fr/> vers Yahoo! Mail