Using Spring notations in custom converters

98 views
Skip to first unread message

dylan

unread,
Feb 8, 2013, 11:02:58 AM2/8/13
to dozer-...@googlegroups.com
I'm having an issue that's been quite frustrating to deal with. We're using Dozer to map between DTOs and JPA Entity objects. So, for complex objects (those composed of other domain objects) we'd like to call the Dozer mapping for the member objects in the converter. Right now I'm attempting to use the  <context:component-scan base-package="foo.bar.transform.converters"/> notation to let Spring manage the converters. However, the "transformer" member remains null, which needless to say is a problem. We're able to access the transformer successfully elsewhere in the system using autowiring, so there's no overall issue with that. However, in this class the wiring just silently fails.

Any help would be GREATLY appreciated!

The relevant code is:

foo.bar.transform.converters;

{imports}

@Component
public class RegionalOfficeToEntityConverter implements CustomConverter {
    @Qualifier("transformer")
    @Autowired
    private Transformer transformer;

    @Override
    @Transactional
    public Object convert(Object existingDestinationFieldValue, Object sourceFieldValue, Class<?> destinationClass,
                          Class<?> sourceClass)
    {
        if (sourceFieldValue == null) {
            return sourceFieldValue;
        }

        if (sourceFieldValue instanceof RegionalOffice) {
            RegionalOffice office = (RegionalOffice) sourceFieldValue;
            RegionalOfficeEntity entity = new RegionalOfficeEntity();
            transformer.map(office, entity);
            return entity;
        }

        if (sourceFieldValue instanceof RegionalOfficeEntity) {
            RegionalOfficeEntity entity = (RegionalOfficeEntity) sourceFieldValue;
            RegionalOffice office = new RegionalOffice();
            transformer.map(entity, office);
            return office;
        }

        return null;
    }

}

dylan

unread,
Feb 8, 2013, 11:08:24 AM2/8/13
to dozer-...@googlegroups.com


On Friday, February 8, 2013 11:02:58 AM UTC-5, dylan wrote:

Oops, the line:
 
foo.bar.transform.converters;

should read:

package foo.bar.transform.converters;

Sorry.

dylan

unread,
Feb 8, 2013, 1:51:21 PM2/8/13
to dozer-...@googlegroups.com
It turns out that we don't need to do this after all. Sorry if I wasted anyone's time...

Reply all
Reply to author
Forward
0 new messages