modelmapper: ModelMapper: Does not map nested collections of List

I have similar example like below:

public class FirstObject {
    private List<SecondObject> myListOne;
    ...only getter method...
    ...no setter method for the list due to it is generated from wsdl 
}
public class SecondObject {
    private List<ThirdObject> myListTwo;
    ...only getter method...
    ...no setter method for the list due to it is generated from wsdl
}
public class ThirdObject {
    private String firstName;
    private String lastName;
    ...setters and getters...
}

FirstObject rq = new FirstObject();
...fills some data...

ModelMapper modelMapper = new ModelMapper();
FirstObjectDTO = modelMapper.map(rq, FirstObjectDTO.class);

The main issue are setter methods for the lists. If you try with PropertyMap or even with Providers you have to use setter methods and I cannot make them manually because all objects will be regenerated from wsdl each time when I run mvn eclipse:eclipse command.

In case that we have setter methods everything will work properly.

Is there any solution how to make this with Converter??

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 15 (7 by maintainers)

Most upvoted comments

This configuration should work:

ModelMapper modelMapper = new ModelMapper();
modelMapper.getConfiguration()
      .setFieldMatchingEnabled(true);
      .setFieldAccessLevel(AccessLevel.PRIVATE);
      .setSourceNamingConvention(NamingConventions.JAVABEANS_MUTATOR);

It enables field mathcing, set the access level as private, and the source naming convention as Mutator to avoid multiple matches with getters.

Nice! @pachoyan - thanks for your kindly answer, that was really helpful!

No problem, I will take a look. Thanks for giving the reproducible sample code.