Does your getListeComptes() method return the actual ArrayList or a copy
of it? Unfortunately, Castor will actually attempt to incrementally add
the items to the ArrayList returned from the getter. If it returns a
copy then that explains why the list is empty after unmarshalling. There
are two workarounds:
1. Return the actual list reference instead of a copy
-or-
2. Specify an add method instead of the actual list mutator, for example:
set-method="addListeCompte"
where you have a method defined as such:
public void addListeCompte(Compte compte) {
_myListCompte.add(compte);
}
HTH,
--Keith
Bhatia Saurab (CHA) wrote:
Gentlemen,
I also tried using the approach listed on the castor site to get my
unmarshalling to work but to no avail yet :-(. This is the xml I am
trying to unmarshall ...
Please note that marshalling works just fine thanks to Castor...If you
need any classes, I would be glad to post ...
Thanks a lot and I am sure there is solution somewhere...maybe I should
try another way to unmarshal. I am not using descriptors since there
arent really any constraints to define yet....
<?xml version="1.0" encoding="UTF-8"?>
<TCM>
<Compte>
<ReferencePersonne>14602769</ReferencePersonne>
<TypeImpot>90</TypeImpot>
<AnneeFiscale>2002</AnneeFiscale>
<NumeroOrdre>1</NumeroOrdre>
</Compte>
<Personne>
<ReferencePersonne>14602769</ReferencePersonne>
</Personne>
</TCM>
-------------------------------------------------------------------
TcmMdlListeAExporter listeLue = null ;
Unmarshaller unmarshaller = null;
InputSource is = null;
try
{
if (pFile.exists())
is = new InputSource(new FileReader(pFile));
// Create a new Unmarshaller
unmarshaller = new Unmarshaller(TcmMdlListeAExporter.class);
unmarshaller.setMapping(pMapping);
// Unmarshal the person object
listeLue = (TcmMdlListeAExporter)unmarshaller.unmarshal(is);
} catch ....
------------------------------------------------------------------------
*De :* Bhatia Saurabh (CHA) [mailto:[EMAIL PROTECTED]
*Envoyé :* lundi, 7. novembre 2005 13:40
*À :* [email protected]
*Objet :* [castor-user] Problem while unmarshalling
Hi,
A) I am only using a mapping file for marshalling and unmarshalling
"sans descriptors" since its supposedly quite straightforward and I dont
have many XML schema constraints to specify in the descriptors anyway.
It works all fine for marshalling but the unmarshalling doesnt work at all.
unmarshaller = new Unmarshaller(pMapping);
listeLue = (TcmMdlListeAExporter)unmarshaller.unmarshal(new
InputSource(new FileReader(file)));
My "listeLue" variable which is an ArrayList is always empty after
execution of this statement. Maybe I should unmarshall another way…
Thanks in advance
<mapping>
<class name="tcm.mdl.TcmMdlListeAExporter" auto-complete="false">
<map-to xml="TCM"/>
<field name="_listeComptes" type="tcm.mdl.TcmMdlCompte"
collection="arraylist" get-method="getListeComptes"
set-method="setListeComptes">
<bind-xml name="Compte" node="element"/>
</field>
<field name="_listePersonnes" type="tcm.mdl.TcmMdlPersonne"
collection="arraylist" get-method="getListePersonnes"
set-method="setListePersonnes">
<bind-xml name="Personne" node="element"/>
</field>
</class>
<class name="tcm.mdl.TcmMdlCompte" auto-complete="false">
<map-to xml="Compte"/>
<field name="_refPersonne" type="string"
get-method="getRefPersonne" set-method="setRefPersonne">
<bind-xml name="ReferencePersonne" node="element"/>
</field>
<field name="_typeImpot" type="string" get-method="getTypeImpot"
set-method="setTypeImpot">
<bind-xml name="TypeImpot" node="element"/>
</field>
<field name="_anneeFiscale" type="string"
get-method="getAnneeFiscale" set-method="setAnneeFiscale">
<bind-xml name="AnneeFiscale" node="element"/>
</field>
<field name="_numeroOrdre" type="string"
get-method="getNumeroOrdre" set-method="setNumeroOrdre">
<bind-xml name="NumeroOrdre" node="element"/>
</field>
</class>
<class name="tcm.mdl.TcmMdlPersonne" auto-complete="false">
<map-to xml="Personne"/>
<field name="_referencePersonne" type="string"
get-method="getReferencePersonne" set-method="setReferencePersonne">
<bind-xml name="ReferencePersonne" node="element"/>
</field>
</class>
</mapping>
-------------------------------------------------
If you wish to unsubscribe from this list, please
send an empty message to the following address:
[EMAIL PROTECTED]
-------------------------------------------------