Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6031797
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T05:14:18+00:00 2026-05-23T05:14:18+00:00

I have deep property mapping in my application (from domain objects to DTO, and

  • 0

I have deep property mapping in my application (from domain objects to DTO, and the reverse), similar to next example:

...

<field>
    <a>employee.id</a>
    <b>employeeId</a>
</field>

...

When Dozer converts Domain to DTO, it maps employee.id to employeeId, and that is ok.
When Dozer converts DTO to Domain, it maps employeeId to a new Employee instance with id=employeeId.

I want to create some logic for this deep property mapping, but i just can’t figure out solution. I tried to implement CustomConverter(or extend DozerConverter) but Dozer passes me Integer type as source and destination class(and expect Integer as result).

EDIT:
More precisely, what i need is to map employee in Domain to null if employeeId in DTO is 0.

Is this possible?

Any advice?

EDIT ACCORDING TO ANSWERS:
I solve problem with field-level custom converter. Instead of earlier, above mentioned, mapping, now i have something like this…

...

<field custom-converter="ManyToOneIdMapper" custom-converter-param="id">
    <a>employee</a>
    <b>employeeId</b>
</field>

...

In ManyToOneIdMapper i have…

public class ManyToOneIdMapper implements ConfigurableCustomConverter{

//...
//parameter field declaration, setParameter and getParameter implementations etc.
//...

public Object convert(Object existingDestinationFieldValue, Object sourceFieldValue, 
        Class<?> destinationClass, Class<?> sourceClass) {
    try {

        if(sourceClass.equals(Integer.class)){
            Integer src=(Integer)sourceFieldValue;

            if(src==null || src==0)
                return null;

            String setterName=formatMethodName("set", getParameter());
            Method setterMethod=destinationClass.getMethod(setterName, Integer.class);
            Object instance=destinationClass.newInstance();

            setterMethod.invoke(instance, src);

            return instance;
        }else{    
            if(sourceFieldValue==null)
                return 0;

            String getterName=formatMethodName("get", getParameter());
            Method getterMethod=sourceClass.getMethod(getterName);
            Object instance=getterMethod.invoke(sourceFieldValue);

            return instance;
        }
    } catch (Exception e){}
    return null;
}

/**
 * @return - method name (most often setter or getter)  according to fieldName.
 * For example formatMethodName("get", "id") returns "getId"
 */
protected String formatMethodName(String methodPrefix, String fieldName){
    String trimmedFieldName=fieldName.trim();
    String firstLetter=String.valueOf(trimmedFieldName.charAt(0));
    String capitalizedFirstLetter=firstLetter.toUpperCase();
    String methodName=methodPrefix+""+capitalizedFirstLetter+""+fieldName.substring(1);

    return methodName;
}

custom-converter-param is just name of id-field in Domain object. With that name, i just call setter or getter method in my converter. Probably, it is not the happiest solution, but it works for my problem scenario.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T05:14:19+00:00Added an answer on May 23, 2026 at 5:14 am

    You want a CustomConverter to map the parent object, for example:

    Domain

    class PersonA {
        ...
        int employeeId;
        ...
    }
    

    DTO

    class PersonB {
        ...
        Employee employee;
        ...
    }
    
    class Employee {
        ...
        int id;
        ...
    }
    

    You want to map the two classes PersonA and PersonB using a CustomConverter, this will let you construct them what ever way you want.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Anybody have a good example how to deep clone a WPF object, preserving databindings?
I have two objects of the same type and need to copy property values
I have a property list which I read into an NSDictionary, from which I
I have a crash that is happening deep within UIKit for some reason; an
I have a hierarchy of tables 3 levels deep (QualificaionType has many QualificationGroups, which
I have a data object that is deep-cloned using a binary serialization. This data
I have an XML structure that is 4 deep: <?xml version=1.0 encoding=utf-8?> <EmailRuleList xmlns:xsd=EmailRules.xsd>
I have a xml which is max 3 levels deep. Now by using C#
I have a tree data structure that is L levels deep each node has
I have a winform app that has tabcontrols that are 3 layers deep. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.