简体   繁体   中英

Dozer enum to enum mapping

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);

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM