3

Why doesn't this work with Dozer? What would I have to do to make it happen? We have a gazillion enums, and sometimes we just need to map between them. Any way we could just configure dozer to do this without writing custom stuff?

enum EnumOne{ TEST1, TEST2 }
enum EnumTwo{ TEST1, TEST2 }

Mapper dozerMapper;

dozerMapper.map(EnumOne.TEST1, EnumTwo.class);
Sully
  • 14,672
  • 5
  • 54
  • 79
tuxbear
  • 551
  • 4
  • 13
  • Did you solve it? if so, can you provide your solution? I'm running into the same problem. Enums are mapped fine when they are mapped as part of a larger POJO, but if I just want to map the Enum alone it doesn't work. – black666 Jan 22 '14 at 16:16
  • No, ended up writing a custom mapper for enums. Our mappers have a dozer mapper internally, and now they derive from a base class that can map enums by name. – tuxbear Jan 23 '14 at 18:18

1 Answers1

0

It doesn't work because Dozer relies on the existence of a public constructor, which is illegal for an enum. You can infer this from the exception when you try to map them:

Exception in thread "main" org.dozer.MappingException: 
java.lang.NoSuchMethodException: DestinationEnum.< init >()

It's looking for a constructor that doesn't exist.

There's no way around it except as black666 said, it has be part of a bigger POJO. That's the way it's been shown in the documentation.

Ray
  • 3,864
  • 7
  • 24
  • 36