Shrinidhi Achar - 2015-12-05

Hi,

I am new to using Dozer and I am using it to map objects of JAXB generated classes to/from application model classes. I am noticing that Dozer does not map attributes that are marked default in the schema because the getter for such attibutes is as follows:

public Object get<Attibute>(){
    if( attribute == null ){
        return <default-value>;
    }
    return attirbute;
}

For such attributes, when source object has the default value, Dozer does not set the value in the destination [JAXB generated class] object as it checks if the value being mapped is already set in the destination object by invoking the getter on the destination object. Since the getter retrieves the default value [which is not really set in the attribute], Dozer does not invoke the setter for this attribute with the default value.

I am currently facing the problem for an Enum attribute. I couldn't find any solution to this apart from implementing a DozerEventListener and overriding the post mapping method to invoke the setter by reflection if the value of the field [retrieved using reflection] is not the value intended in the destination object. Can you suggest any other solution to the problem I am facing.

Regards,
Shrinidhi Achar

 

Last edit: Shrinidhi Achar 2015-12-06