Thursday, July 9, 2009

Handling ArrayList using Betwixt

I faced initial isues with using Betwixt for ArrayList. When researching on internet, i found lot of people sailing on the same boat. I came to a point where i was about to give up on betwixt arraylist, but then thought of giving one last try. This time i succeeded. I had the debugger on, noticed that List was causing issues. Betwixt was not able to use interfaces. After changing below code and making some alterations my transformation started working.

private List<Category> categories = new ArrayList<Category>();
private ArrayList<Category> categories = new ArrayList<Category>();

Below are the sample code from my application:


<class name="com.wwe.syndication.SyndicationBean">
<element name="entry">
<element name="id" property="syndicationBeanID">
<element name="title" property="title">
<element name="updated" property="tpAssetGenericConfig">
<element property="categories" updater="addcategories" >
<element property="photos">
<element name="content" property="description">
<element name="asset_type" property="assetType">

<class name="com.wwe.beans.Category">
<element name="category">
<attribute name="term" property="category">

Syndication Bean is a normal POJO which contains ArrayList of Categories.
private ArrayList<Category> categories = new ArrayList<Category>();

NOTE: Dont use interfaces, use classes directly. In the above example, if List is used for declaration, betwixt transformation throws errors. The problem with Betwixt is all errors are thrown as DEBUG statements.

My category class:
public class Category {
private String category;
private String type;
//setter & getters

If you are struck with Betwixt ArrayList transofrmations, email me your code, I would try to fix them.