Dozer trying to map a class to its interface
Asked Answered
N

1

8

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?

Narration answered 1/7, 2013 at 9:16 Comment(1)
Do you have Dozer configuration related to this class?Prevailing
P
3

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.

Prefect answered 20/7, 2014 at 21:37 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.