#75 inappropriate subclass mappings applied

closed
None
5
2007-05-21
2007-03-05
No

Dozer is attempting to apply a mapping for a destination subclass when processing an instance of it's parent class as the destination.
Example:
Take the class heirarchy: Child -> Parent ( Child extends Parent). Class child has a property (childProp) that is not present in the Parent class.

The mapping file contains a one-way mapping from class SourceData to class Child.
Calling dozerMapper.map(sourceData, destination) results in a MappingException:
net.sf.dozer.util.mapping.MappingException: Unable to determine write method for field: childProp class: class dozer.test.Parent

Some debugging has turned up that Dozer is trying to apply the SourceData -> Child mapping when mapping to an instance of Parent. It does this because ClassMapFinder.findClassMap() does not find a direct mapping so it calls findInterfaceOrAbstractMapping() to search for one in the list of custom mappings. The logic in findInterfaceOrAbstractMapping() checks that the class of the destination object (Parent) is assignable from the mapping's destination class (Child), which it is so it selects this custom mapping (SourceData -> Child), which is clearly not going to work.

I found a workaround by declaring an empty mapping for SourceData -> Parent, but this doesn't seem like the right thing to do. Is there another solution?

I'm attaching some source code with a unit test to illustrate the problem.

Discussion

  • Adam Lewandowski

    Logged In: YES
    user_id=430214
    Originator: YES

    File Added: DozerSubclassMappingTest.xml

     
  • Adam Lewandowski

    test data class

     
  • Adam Lewandowski

    Logged In: YES
    user_id=430214
    Originator: YES

    File Added: Child.java

     
  • Adam Lewandowski

    Logged In: YES
    user_id=430214
    Originator: YES

    File Added: Parent.java

     
  • Adam Lewandowski

    test data class

     
  • Adam Lewandowski

    Logged In: YES
    user_id=430214
    Originator: YES

    File Added: SourceData.java

     
  • Adam Lewandowski

    test data class

     
  • Ted Velkoff

    Ted Velkoff - 2007-03-13

    Logged In: YES
    user_id=769604
    Originator: NO

    I've also seen this. There are problems with MappingProcessor and CustomConverterContainer. I will follow up with code and tests that illustrate the problem.

     
  • Franz Garsombke

    Franz Garsombke - 2007-05-02

    Logged In: YES
    user_id=550744
    Originator: NO

    I will research and get this into the next release.

     
  • Franz Garsombke

    Franz Garsombke - 2007-05-02
    • assigned_to: nobody --> fgarsombke
     
  • Franz Garsombke

    Franz Garsombke - 2007-05-07
    • status: open --> pending
     
  • Franz Garsombke

    Franz Garsombke - 2007-05-07

    Logged In: YES
    user_id=550744
    Originator: NO

    This seems to be the same issue as 1486105. I have fixed this and will be in the next release.

    Franz

     
  • Franz Garsombke

    Franz Garsombke - 2007-05-21
    • status: pending --> closed
     

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks