Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

#113 Problem with Java 1.5 enum and inheritance

Dozer v4.4
closed
None
5
2008-12-12
2007-10-03
joz
No

There is a problem with the handling of inherited enums in java 1.5
I first declare an enum using inheritance :

public enum MyType
{
FOO
{
@Override
public String display() { return "foo";}
},
BAR
{
@Override
public String display() { return "bar"; }
};

public abstract String display();
}

Then I declare a bean containinng the following
enum
public class MyBean
{
private MyType type;
// Getters and setters here...
}

When I try to map this bean to itself, Dozer throws an Exception.
The point here is that dozer tries to instantiate the enumeration to set it in the destination bean because it doesn't recognize the value as an enum. This is because the values here (FOO and BAR) are not instances of an enum class, but each one has a type that is derivated from the enum.
My investigations showed that the problem is in the class MappingProcessor, in method mapOrRecurseObject(),
line 410 in version 4.1. The way enum values are detected is erroneous because the method isEnum()
returns true only is a class is a java declared enum,
and this is not the case for the types of my FOO and BAR value. We should call first the method getDeclaringClass() which returns the Class of the enum associated to FOO and BAR (in this case, MyType.class) and the isEnum() method has to be invoked on this one.

Discussion

  • - jieryn -
    - jieryn -
    2008-09-04

    Logged In: YES
    user_id=2204652
    Originator: NO

    What is the status of this? It still seems to be failing over a year after bug report. Erk. This is a blocker for me..

     


  • 2008-09-05

    Logged In: YES
    user_id=731522
    Originator: NO

    I think you can't expect someone to fix this, as well as any other bugs in this tracker, as it seems to me the project has been abandoned by its original administrators/contributors.
    Have a look, no bug, nor any feature request has received a feedback from them for almost a year!!!
    Same thing in the forums, no answer!!!

    It's hopeless! :((((

     
  • dmitry (lv)
    dmitry (lv)
    2008-10-18

    • milestone: --> 888638
    • assigned_to: nobody --> sterala
     
  • dmitry (lv)
    dmitry (lv)
    2008-12-06

    • milestone: 888638 --> Dozer v4.4
    • assigned_to: sterala --> cchou
     
  • Chia-Chou Hung
    Chia-Chou Hung
    2008-12-12

    • status: open --> closed
     
  • Chia-Chou Hung
    Chia-Chou Hung
    2008-12-12

    patch for 1806780

     
    Attachments
  • Chia-Chou Hung
    Chia-Chou Hung
    2008-12-12

    Hi,
    Sorry for the late response. This issue has been fixed as attached. Feel free to let us know if you still have the same problems.

    Thanks,

    Chia-Chou
    File Added: patch_1806780.zip