Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dozer trying to map a class to its interface

With my data model, which is basically a tree with parents children, Dozer is having issues successfully mapping them as it interprets a field (which uses an interface-type as a parameter) as being a class, and trying to instantiate it with a constructor. This results in the following exception;

ERROR [MappingProcessor] - Field mapping error -->
MapId: null
Type: null
Source parent class: com.*.shared.model.Module
Source field name: parent
Source field type: class com.*.shared.model.Datawarehouse
Source field value: com.*.shared.model.Datawarehouse@706ce458
Dest parent class: com.*.shared.model.Module
Dest field name: parent
Dest field type: com.*.shared.model.Model
org.dozer.MappingException: java.lang.NoSuchMethodException: com.*.shared.model.Model.<init>()

This is a same-class mapping, and Whilst Dozer correctly identifies the parent field on the source class as being of type Datawarehouse, because the set method on the Module class for its parent uses the Model interface as its parameter, it seems to be attempting to instantiate the type of Model, which of course fails as Model is an interface with no constructor, rather than Datawarehouse, as the source class field indicates.

I know about using bean-factories to alter the standard mapping behaviour, but I'm surprised that this would be the only way to resolve this issue. It seems to me that Dozer already has the information it needs since it identifies the source class type, and unusual to me that it would try to instantiate the interface specified by the setter's signature rather than the type it is attempting to map over.

Any suggestions?

like image 396
DavidH Avatar asked Jul 01 '13 09:07

DavidH


1 Answers

You coukd solve this problem by using dozer a-hint and b-hint tags in dozer xml configuration. Specifying which class shoukd dozer instatiate instead of the interface.

like image 95
vbazaga86 Avatar answered Sep 19 '22 00:09

vbazaga86