Butjadinger Str. 34a 28197 Bremen
++49 173 2494181

Converter Populator

Converter Populator

Converter and Populator


For a better separation of concerns it is good practice to provide view objects which are independent from the business logic; the solution ist the Converter and Populator pattern. The question is: How to fill. Inspired from SAP Commerce Cloud and a video from Michael Albrecht – only in German (but there is also a link to an English version) I implemented a converter/populater pattern with some lines of code in java. From my point of view not the implementation is important but the pattern itself. In the above Video Michael explains how it can help in real software projects.

For each Bean (Entity, Business Object, what else) you provide a Populator object, which populates the properties, which should be shown in the view. A converter collects all the populators which are necessary to fulfill the work.

Converter an Populator concrete

You want to provide contact details as shown in Michaels video the Converter and Populator pattern helps you a lot. The Name is taken from a User-Object, the Address of an Address-Object. All data are collected in a ContactView-Object. So you provide a populator, which populates the prename, lastname from Customer-Object. You provide a second polulator, which provides the address details from the Address-Object. You can stick everything together to a converter e.g. with Spring.

<bean name="userPopulator" class="org.mwolff.populator.UserDataPopulator"/>
<bean name="addressPopulator" class="org.mwolff.populator.AddressPopulator"/>

<bean name="contactconverter" class="org.mwolff.converter.GenericConverter">
     <property name="populatorlist">
            <ref bean="userPopulator"/>
            <ref bean="addressPopulator"/>

Putting Converters and Populators together ist quite easy:

GenericConverter contactconverter;

    public void foo() {

        Address address = magicGetAddress(); // wherever it is located
        Customer customer = magicGetCustomer(); // wherever it is located
        ContactView target = new ContactView();


If you want to add some more properties from other sources, just create a new populator in the list of populators and put another source into the converter. Thats its. If the property names are equal, you can just take a GenericPopulator, otherwise you’ve provide a litte bit code, how to transform.

public class UserDataPopulator implements Populator<Customer, ContactView> {

    public void convert(Customer source, ContactView target) {


Check out: https://gitlab.com/mannewolff/simple-converter.git
Resources for Converters and Populators can be downloaded here: https://repo1.maven.org/maven2/org/mwolff/simple-converter/1.0.2/
Documentation: Comes soon, but you can browse the tests.
Include it in your project:


For other frameworks as gradle etc. browse here:

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert.

Diese Website verwendet Akismet, um Spam zu reduzieren. Erfahre mehr darüber, wie deine Kommentardaten verarbeitet werden.