DozerConverter API - Converter abstraction

222 views
Skip to first unread message

Laurent Sgualdino

unread,
May 5, 2017, 4:56:31 AM5/5/17
to Dozer Mapper
Hello,

I would like to share some experiments with the DozerConverter API.

I created a test case in a maven project attached.

I would like to map an AfterSaleServiceAction bean to a HumanInteraction bean.
The need is simple, if an AfterSaleServiceAction has a customer and an employee associated, just map it to two Interviewer's and Interviewee's identification beans.
As Customer and Employee don't have the same fields for names, I have to map each beans with a custom converter.

As the Identification is composed of a field that must contain the fullname, I created an abstract converter, and two subclass containing only the fullname construction logic.

When I try my test case, Dozer throws an exception when instantiation the subclass converter:

org.dozer.MappingException: java.lang.InstantiationException: com.sample.dozer.converter.EmployeeIdentificationConverter
at org.dozer.util.MappingUtils.throwMappingException(MappingUtils.java:82)
at org.dozer.util.ReflectionUtils.newInstance(ReflectionUtils.java:366)
at org.dozer.MappingProcessor.mapUsingCustomConverter(MappingProcessor.java:1015)
at org.dozer.MappingProcessor.mapFromFieldMap(MappingProcessor.java:364)
at org.dozer.MappingProcessor.mapField(MappingProcessor.java:307)
at org.dozer.MappingProcessor.map(MappingProcessor.java:267)
at org.dozer.MappingProcessor.mapToDestObject(MappingProcessor.java:216)
at org.dozer.MappingProcessor.createByCreationDirectiveAndMap(MappingProcessor.java:196)
at org.dozer.MappingProcessor.mapGeneral(MappingProcessor.java:170)
at org.dozer.MappingProcessor.map(MappingProcessor.java:104)
at org.dozer.MappingProcessor.map(MappingProcessor.java:99)
at org.dozer.DozerBeanMapper.map(DozerBeanMapper.java:120)
at com.sample.dozer.service.HumanInteractionServiceStub.from(HumanInteractionServiceStub.java:13)
at com.sample.dozer.service.HumanInteractionServiceStubTest.stubTestNotInitializedResources(HumanInteractionServiceStubTest.java:35)
...
Caused by: java.lang.InstantiationException: com.sample.dozer.converter.EmployeeIdentificationConverter
at java.lang.Class.newInstance(Class.java:427)
at org.dozer.util.ReflectionUtils.newInstance(ReflectionUtils.java:364)
... 36 more
Caused by: java.lang.NoSuchMethodException: com.sample.dozer.converter.EmployeeIdentificationConverter.<init>()
at java.lang.Class.getConstructor0(Class.java:3082)
at java.lang.Class.newInstance(Class.java:412)
... 37 more


Any advice on that point?

Thanks,
dozer-conversion.zip

jpingus

unread,
Mar 8, 2019, 5:33:52 AM3/8/19
to Dozer Mapper
Had the same exactly, 
Dozer expects a 0 parameter constructor to be provided.

i.e. replacing 
  public CustomerIdentificationConverter(Class<CustomerView> prototypeA,
      Class<Identification> prototypeB) {
    super(prototypeA, prototypeB);
  }

with
  public CustomerIdentificationConverter() {
    super(CustomerView.class, Identification.class);
} should do the trick (at least this is how I solved my issue)...
Reply all
Reply to author
Forward
0 new messages