Question

I've got a dozer mapping that returns a User through a custom converter by the parameter. This works as it should, but now this User should be converted to a Official.

I tried to do this by letting the converter return the User and making another dozer xml file to convert the User to the Official. I added this xml file to the dozerfactory, but it doesn't seem to be invoked.

I'm getting: "Exepected Official, actual: User". How could I let the userToOfficial.xml file be invoked?

First dozer file:

<mapping>
<class-a>be.someClass</class-a>
<class-b>be.anotherClassWithOfficial</class-b>


<field custom-converter-id="OfficialConverter">
  <a>someString</a>
  <b>official</b>
</field>

tried adding, but doesn't work:

<b-hint>be.Official</b-hint>

the second dozer file (should be invoked after the converter but isn't):

<mapping>
<class-a>be.User</class-a>
<class-b>be.Official</class-b>
<field>
  <a>mail</a>
  <b>email</b>
</field>

The converter:

public class OfficialConverter implements CustomConverter {

/** The ldap local. */
private UserLocal userLocal;

@Override
public Object convert(Object existingDestinationFieldValue, Object sourceFieldValue,
        Class < ? > destinationClass, Class < ? > sourceClass) {
    if (sourceFieldValue == null) {
        return null;
    }
    if (sourceFieldValue instanceof String) {
        User user= userLocal
                .getUserByLogin((String) sourceFieldValue);
        return user;

    }
    return null;
}

public UserLocal getUserLocal() {
    return userLocal;
}


public void setUserLocal(UserLocal userLocal) {
    this.userLocal= userLocal;
}

}

Was it helpful?

Solution

As per your customconverter, it seems you are mapping from String to User and now instead of User, you want an object of Offical. Right? and you want to automate this User to Offical conversion using dozer. Right? If yes, then the you need to invoke the new dozer in the custom converter itself using mapper.map() method. Your current use-case will not invoke it automatically.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top