Nontrivial Dozer Mappings

I try my best to get a Dozer to bend my will for something that, in my opinion, should be fairly simple. I have two similar models that I want to compare with each other, but I have a deeper hierarchy than the other, and this causes me problems when working with collections. Consider the following classes:

Source classes:

class Foo {
    String id;
    NameGroup nameGroup; 
    // Setters/Getters
}

class NameGroup {
    private List<Name> names;
    // Setters/Getters
}

class Name {
    private String nameValue;
    // Setters/Getters
}

Target classes:

class Bar {
    private String barId;
    private BarNames barNames;
    // Setters/Getters
}

class BarNames {
    private List<String> names;
    // Setters/Getters
}

Now I need the following one-way mappings:

Foo.id -> Bar.barId // Simple enough

But then I need:

Foo.nameGroup.names.nameValue -> Bar.barNames.names

Therefore, each instance Namein Foo.nameGroup.namesshould result in being added Stringto the list BarNames.names. Is it possible?

+5
source share
1 answer

Dozer, "Name" String.

Dozer (http://dozer.sourceforge.net/documentation/simpleproperty.html):

Dozer . Dozer : ( )

...

, String

...

, ( ), . , :

<mapping>
  <class-a>com.test.bar.Bar</class-a>
  <class-b>com.test.foo.Foo</class-b>
  <field>
    <a>barId</a>
    <b>id</b>
  </field>
  <field>
    <a>barNames.names</a>
    <b>nameGroup.names</b>
    <a-deep-index-hint>java.lang.String</a-deep-index-hint>
    <b-deep-index-hint>com.test.foo.Name</b-deep-index-hint>
  </field>
</mapping>
+5

All Articles