1

Using SuperCSV with Dozer (version 2.2.0), I've been able to successfully map data into a List. However, I now have a case where I want to map into a List of Lists. In the object I'm trying to map to, I have a field that looks something like this:

List<List<String>> myListOfLists;

For my field mapping I did this:

"myListOfLists[0][0]", "myListOfLists[0][1]", "myListOfLists[1][0]", etc.

However, this results in the following error:

org.dozer.MappingException: No read or write method found for field (myListOfLists[0]) in class (class com.foo.MyClassBeingMappedTo)

I can't seem to find any examples of nested collections, but it seems like this should be possible. Is there a way I can map the data into my List<List<String>> field?

dnc253
  • 39,967
  • 41
  • 141
  • 157
  • I think this is a limitation of Dozer - I don't think it can handle nested Lists. You'd think you could use `myListOfLists[0].[0]` but it seems to ignore the trailing `.[0]` altogether, resulting in a `ClassCastException` when you access your List (as it's actually a String!). – James Bassett Jan 10 '15 at 03:53

1 Answers1

0

I got around this by creating a wrapper class for my inner List. I created an inner class like this:

public static class InnerListWrapper
{
    private List<String> innerList;

    public List<String> getInnerList()
    {
        return innerList;
    }
    public void setInnerList(List<String> innerList)
    {
        this.innerList = innerList;
    }
}

Then my outer List looks like this:

List<InnerListWrapper> myListOfLists;

Then the fields mapping is simply "myListOfLists[0].innerList[0]","myListOfLists[0].innerList[1]", ""myListOfLists[1].innerList[0]", etc.

Not the cleanest, but like the comment above says, Dozer doesn't seem to support nested Lists. So you have to add another class in between.

dnc253
  • 39,967
  • 41
  • 141
  • 157