#249 copy-by-reference ignored when class in a Set

Dozer v5.2.2
closed-fixed
5
2014-08-13
2010-03-10
No

When I configure a certain class to be copied by reference, this configuration is ignored (Dozer tries to init a new Instance (fails because of private Constructor)) when this class exists in a Set.
If this class exists in a "normal" property, the configuration works.

Attached you find a small demo that shows the problem.

The demo at a glance (all Sources can be found in the attachment):

...
<configuration>
<copy-by-references>
<copy-by-reference>dozerTest.SimpleTypesaveEnum</copy-by-reference>
</copy-by-references>
</configuration>
...

TestDozer.java:

...
// Simple property
ClassA classA = new ClassA();
classA.setSimpleTypesaveEnum(SimpleTypesaveEnum.TWO);
ClassB classB = new ClassB();

tempMapper.map(classA, classB);
System.out.println(classB.getSimpleTypesaveEnum().toString());

// Property within Set
Set<SimpleTypesaveEnum> tempSet = new HashSet<SimpleTypesaveEnum>();
tempSet.add(SimpleTypesaveEnum.TWO);

ClassC classC = new ClassC();
classC.setSimpleTypesaveEnumSet(tempSet);
ClassD classD = new ClassD();
tempMapper.map(classC, classD);
System.out.println(classD.getSimpleTypesaveEnumSet().iterator().next().toString());
...

Output:

...
INFO: Successfully loaded custom xml mappings from URL: [file:/C:/path/to/dozerTest/mapping-configuration.xml]
TWO
10.03.2010 10:39:13 org.dozer.factory.DestBeanCreator create
SCHWERWIEGEND: Error trying to use XMLBeanFactory.
org.dozer.MappingException: Factory class of Bean of type dozerTest.SimpleTypesaveEnum not found.
at org.dozer.util.MappingUtils.throwMappingException(MappingUtils.java:93)
at org.dozer.factory.XMLBeanFactory.createBean(XMLBeanFactory.java:54)
at org.dozer.factory.DestBeanCreator.createFromFactory(DestBeanCreator.java:147)
at org.dozer.factory.DestBeanCreator.create(DestBeanCreator.java:100)
at org.dozer.MappingProcessor.mapCustomObject(MappingProcessor.java:436)
at org.dozer.MappingProcessor.mapOrRecurseObject(MappingProcessor.java:406)
at org.dozer.MappingProcessor.addToSet(MappingProcessor.java:666)
at org.dozer.MappingProcessor.mapCollection(MappingProcessor.java:511)
at org.dozer.MappingProcessor.mapOrRecurseObject(MappingProcessor.java:394)
at org.dozer.MappingProcessor.mapFromFieldMap(MappingProcessor.java:303)
at org.dozer.MappingProcessor.mapField(MappingProcessor.java:249)
at org.dozer.MappingProcessor.map(MappingProcessor.java:218)
at org.dozer.MappingProcessor.map(MappingProcessor.java:163)
at org.dozer.MappingProcessor.map(MappingProcessor.java:128)
at org.dozer.MappingProcessor.map(MappingProcessor.java:123)
at org.dozer.DozerBeanMapper.map(DozerBeanMapper.java:96)
at dozerTest.TestDozer.main(TestDozer.java:44)
10.03.2010 10:39:13 org.dozer.MappingProcessor mapField
SCHWERWIEGEND: Field mapping error -->
MapId: null
Type: null
Source parent class: dozerTest.ClassC
Source field name: simpleTypesaveEnumSet
Source field type: class java.util.HashSet
Source field value: [TWO]
Dest parent class: dozerTest.ClassD
Dest field name: simpleTypesaveEnumSet
Dest field type: java.util.Set
org.dozer.MappingException: java.lang.NoSuchMethodException: dozerTest.SimpleTypesaveEnum.<init>()
at org.dozer.util.MappingUtils.throwMappingException(MappingUtils.java:88)
at org.dozer.factory.DestBeanCreator.newInstance(DestBeanCreator.java:164)
at org.dozer.factory.DestBeanCreator.create(DestBeanCreator.java:95)
at org.dozer.MappingProcessor.mapCustomObject(MappingProcessor.java:436)
at org.dozer.MappingProcessor.mapOrRecurseObject(MappingProcessor.java:406)
at org.dozer.MappingProcessor.addToSet(MappingProcessor.java:666)
at org.dozer.MappingProcessor.mapCollection(MappingProcessor.java:511)
at org.dozer.MappingProcessor.mapOrRecurseObject(MappingProcessor.java:394)
at org.dozer.MappingProcessor.mapFromFieldMap(MappingProcessor.java:303)
at org.dozer.MappingProcessor.mapField(MappingProcessor.java:249)
at org.dozer.MappingProcessor.map(MappingProcessor.java:218)
at org.dozer.MappingProcessor.map(MappingProcessor.java:163)
at org.dozer.MappingProcessor.map(MappingProcessor.java:128)
at org.dozer.MappingProcessor.map(MappingProcessor.java:123)
at org.dozer.DozerBeanMapper.map(DozerBeanMapper.java:96)
at dozerTest.TestDozer.main(TestDozer.java:44)
Caused by: java.lang.NoSuchMethodException: dozerTest.SimpleTypesaveEnum.<init>()
at java.lang.Class.getConstructor0(Class.java:2706)
at java.lang.Class.getDeclaredConstructor(Class.java:1985)
at org.dozer.factory.DestBeanCreator.newInstance(DestBeanCreator.java:160)
... 14 more
Exception in thread "main" org.dozer.MappingException: java.lang.NoSuchMethodException: dozerTest.SimpleTypesaveEnum.<init>()
at org.dozer.util.MappingUtils.throwMappingException(MappingUtils.java:88)
at org.dozer.factory.DestBeanCreator.newInstance(DestBeanCreator.java:164)
at org.dozer.factory.DestBeanCreator.create(DestBeanCreator.java:95)
at org.dozer.MappingProcessor.mapCustomObject(MappingProcessor.java:436)
at org.dozer.MappingProcessor.mapOrRecurseObject(MappingProcessor.java:406)
at org.dozer.MappingProcessor.addToSet(MappingProcessor.java:666)
at org.dozer.MappingProcessor.mapCollection(MappingProcessor.java:511)
at org.dozer.MappingProcessor.mapOrRecurseObject(MappingProcessor.java:394)
at org.dozer.MappingProcessor.mapFromFieldMap(MappingProcessor.java:303)
at org.dozer.MappingProcessor.mapField(MappingProcessor.java:249)
at org.dozer.MappingProcessor.map(MappingProcessor.java:218)
at org.dozer.MappingProcessor.map(MappingProcessor.java:163)
at org.dozer.MappingProcessor.map(MappingProcessor.java:128)
at org.dozer.MappingProcessor.map(MappingProcessor.java:123)
at org.dozer.DozerBeanMapper.map(DozerBeanMapper.java:96)
at dozerTest.TestDozer.main(TestDozer.java:44)
Caused by: java.lang.NoSuchMethodException: dozerTest.SimpleTypesaveEnum.<init>()
at java.lang.Class.getConstructor0(Class.java:2706)
at java.lang.Class.getDeclaredConstructor(Class.java:1985)
at org.dozer.factory.DestBeanCreator.newInstance(DestBeanCreator.java:160)
... 14 more

Discussion

  • Stephan Sann

    Stephan Sann - 2010-03-10

    Small app that demonstrates the problem

     
  • dmitry (lv)

    dmitry (lv) - 2010-05-16
    • milestone: 929386 --> Dozer v5.2.2
    • assigned_to: nobody --> buzdin
    • status: open --> closed-fixed
     
  • dmitry (lv)

    dmitry (lv) - 2010-05-16

    fixed in trunk. Thanks for the proper test case. This feature was not implemented, but it is now.

     

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks