I have such enum:
public enum PartnershipIndicator {
VENDOR("VENDOR"), COPARTNER("COPARTNER"), BUYER("BUYER");
String code;
private PartnershipIndicator(String code) {
this.code = code;
}
public String getCode() {
return code;
}
public static PartnershipIndicator valueOfCode(String code) {
for (PartnershipIndicator status : values()) {
if (status.getCode().equals(code)) {
return status;
}
}
throw new IllegalArgumentException(
"Partnership status cannot be resolved for code " + code);
}
@Override
public String toString() {
return code;
}
}
I need to convert it to String and vice versa. Now, it is done by custom converter. But i want to do it via dozer mappings (if it is possible). If i do not write any mappings to the dozer confing, i get
org.dozer.MappingException: java.lang.NoSuchMethodException: by.dev.madhead.demo.test_java.model.PartnershipIndicator.<init>()
exception. I cannot add default public constructor to enum, as it is not possible. So, i wrote a trick with internal code and valueOfCode() / toString(). It does not work. Then, i've mapped it in dozer config:
<mapping>
<class-a>java.lang.String</class-a>
<class-b create-method="valueOfCode">by.dev.madhead.demo.test_java.model.PartnershipIndicator</class-b>
</mapping>
It does not work. I tried valueOfCode(), one-way mappings. Nothing works. Enum to String conversion does not work too, i get empty Strings. Any ideas?