#354 Duplicate proxy object mapping

Dozer v5.3.2

Dozer does not seem to handle having nested collections with the same proxied objects in them. Here is an example of the scenario that we have.

class Slide {
// fields

class SlideShow extends Document {
List<Slide> slides;

// getter and setters.

class ChapterList extends Document {
List<Chapter> chapters;

// getters and setters

class Chapter {
List<Slide> slides;

// getters and setters

class Presentation {
List<Document> documents;

// getters and setters;

The slide objects in the SlideShow and Chapter are the same, and the list of documents contains SlideShow and ChapterList objects. As they have been retrieved using Hibernate they are proxy objects. The problem is that when it finds the SlideShow objects, it calls deProxy on the Slides and adds them to the list of already mapped objects. However, when it come to map the ChapterList object, it does not call deProxy. This causes Dozer to look in the list of mapped objects for a proxy object, and not find the one that has already been mapped, therefore, creating a new object with the same values.

I realise this is a slightly complicated scenario, and may be difficult to understand, but hopefully there is enough information here.


  • BigHenry

    I've come across this too -- as the Hibernate proxy is not unwrapped, the identity check for previously mapped beans fails, so Dozer fails to maintain referential integrity.

    I've patched org.dozer.MappingProcessor locally to fix the issue:

    private Object mapOrRecurseObject(Object srcObj, Object srcFieldValue, Class<?> destFieldType, FieldMap fieldMap, Object destObj) {
    Object srcFieldValue = MappingUtils.deProxy(srcFieldValue);
    // ...

    But obviously having my own branch isn't ideal.

    Could this fix (or another if you deem this incorrect) be added to the next release please?