I was searching for the same thing yesterday and I came across your post (and I saw it was recent). After some search I managed to overcome this problem so I thought it would be nice to share with you my findings.
I suppose that you defined an POJO for your data and then added all these objects to the HashMap (correct me if I am right).
What I did was to create a new Object that extends HashMap implementation. (In fact you dont have to extend this, you can use the HashMap object itself). So now instead of having objects inside HashMap I directly inserted values for the properties. But lets just add some code blocks in order to clear things :)
Suppose that you have the following PoJO
public class MyPOJO{
private String name;
private String value;
//getters, setters etc..
}
Instead of adding these various objects to a List and providing it as datasource you can use a HashMap this way to define your objects:
Map<String,String> myObject1=new HashMap<String,String>();
myObject1.put("name","Name1");
myObject1.put("value","Value1");
Map<String,String> myObject2=new HashMap<String,String>();
myObject2.put("name","Name2");
myObject2.put("value","Value2");
After defining these objects we can add them in a List and provide it as datasource (JRBeanCollectionDataSource
). So the keys of each HashMap
are considered to be the properties defined in the Columns (the properties of the initial POJO).
I dont know if my solution is the best but it worked for me!