Note that there are some explanatory texts on larger screens.

plurals
  1. PODozer String to enum mapping
    text
    copied!<p>I have such enum:</p> <pre><code>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; } } </code></pre> <p>I need to convert it to String and vice versa. <em>Now, it is done by custom converter.</em> 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</p> <pre><code>org.dozer.MappingException: java.lang.NoSuchMethodException: by.dev.madhead.demo.test_java.model.PartnershipIndicator.&lt;init&gt;() </code></pre> <p>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:</p> <pre><code>&lt;mapping&gt; &lt;class-a&gt;java.lang.String&lt;/class-a&gt; &lt;class-b create-method="valueOfCode"&gt;by.dev.madhead.demo.test_java.model.PartnershipIndicator&lt;/class-b&gt; &lt;/mapping&gt; </code></pre> <p>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?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload