Hi Nabeel,
it seems like there's two slightly wrong mappings that prevent you from
successful (un)marshalling operations:
a) The field mapping for the 'recentTransactions' member of the
'CreditCardVO ' class. In my opinion it shoudl read:
<field name="recentTransactions" collection="arraylist"
type="com.sample.CreditCardTransactionVO">
<bind-xml name="transaction"
location="creditCardsProductDetail/transactions"
node="element" />
</field>
If that alone does not resolve things, please add the following
<map-to/> element to your class mapping for
'com.sample.CreditCardTransactionVO':
<map-to xml="transaction"/>
And finally, why not initialize the
private List<CreditCardTransactionVO> recentTransactions;
member to an empty list ?
If you have any questions towards my suggestions, please feel free to ask.
Regards
Werner
On 09.12.2010 16:01, Nabeel Saad wrote:
Hello,
I've been working for the past couple of hours trying to get my mapping to work
correctly, but I've been struggling.
Here's a sample of the XML that I am trying to pull into a Java object:
//Sample.xml
<?xml version="1.0" encoding="UTF-8"?>
<CreditCardsProductType>
<ProductType>
<productID>123</productID>
<productName>Mastercard</productName>
</ProductType>
<creditCardsProductDetail>
<creditCardBalance>1234</creditCardBalance>
<availableCredit>4321</availableCredit>
<transactions>
<transaction>
<date>2010-01-19T05:39:20.940-05:00</date>
<transactionCategory>Credit</transactionCategory>
<transactionName>Refund</transactionName>
<moneyIn>150</moneyIn>
<moneyOut>0</moneyOut>
</transaction>
<transaction>
<date>2010-01-21T05:39:20.940-05:00</date>
<transactionCategory>Debit</transactionCategory>
<transactionName>Withdrawal</transactionName>
<moneyIn>50</moneyIn>
<moneyOut>0</moneyOut>
</transaction>
</transactions>
</creditCardsProductDetail>
</CreditCardsProductType>
//Sample2.xml --- I use the same exact XML above except that I leave out the
2<transaction> nodes leaving in the<transactions> node. The aim is to get an
initialised but empty list.
I have a couple of classes that handle these, they have getters and setters but
I've pulled them out of the sample below to decrease the size of the posting:
//CreditCardVO.java
public class CreditCardVO implements BaseProductVO {
private BigDecimal currentBalance;
private BigDecimal availableCredit;
private List<CreditCardTransactionVO> recentTransactions;
private String productName;
private String targetProductID;
}
//CreditCardTransactionVO
public class CreditCardTransactionVO {
private DateTime date;
private String transactionName;
private BigDecimal moneyIn;
private BigDecimal moneyOut;
}
The current mapping that I have:
//Mappings.xml
<class name="com.sample.CreditCardVO">
<map-to xml="CreditCardsProductType"/>
<field name="currentBalance" type="big-decimal">
<bind-xml name="creditCardBalance" location="creditCardsProductDetail"
node="element"/>
</field>
<field name="availableCredit" type="big-decimal">
<bind-xml name="availableCredit" location="creditCardsProductDetail"
node="element"/>
</field>
<field name="recentTransactions" type="com.sample.CreditCardTransactionVO"
collection="arraylist">
<bind-xml name="transactions" location="creditCardsProductDetail"
node="element" />
</field>
<field name="productName" type="string">
<bind-xml name="productName" location="ProductType" node="element"/>
</field>
<field name="targetProductID" type="string">
<bind-xml name="productID" location="ProductType" node="element"/>
</field>
</class>
<class name="com.sample.CreditCardTransactionVO">
<field name="moneyIn" type="big-decimal">
<bind-xml name="moneyIn" location="transaction" node="element"/>
</field>
<field name="moneyOut" type="big-decimal">
<bind-xml name="moneyOut" location="transaction" node="element"/>
</field>
<field name="transactionName" type="string">
<bind-xml name="transactionName" location="transaction"
node="element"/>
</field>
<field name="date" type="string" handler="com.castor.DateTimeHandler">
<bind-xml name="date" location="transaction" node="element"/>
</field>
</class>
*******************************************************************************************
*******************************************************************************************
OK, so now that I've defined the environment that I have, let me explain the
issue that I am seeing.
It is mainly to do with the list that is supposed to be put into
recentTransactions. In the current form, what happens, is the following:
- Only one transaction is picked up even though I have two<transaction> nodes.
- When I pull out the transactions, then the recentTransactions list actually
returns a list with one item in it of type CreditCardsTransactionVO with all
it's fields set to null which is not expected.
Any help would be much appreciated. I've read through lots of examples and a lot of the
documentation on the Castor website. I've tried using container="false" on the
recentTransactions field but couldn't seem to get that to work either. When I use the
container attribute, that just returns null for recentTransactions with or without any
transactions.
Any responses would be much appreciated!
Cheers,
Nabeel
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email