Orika mapping of jodatime DateMidnight
<p>I'm trying to map a <code>DateMidnight</code> into a <code>LocalDate</code> using <a href="http://orika-mapper.github.io/orika-docs/index.html" rel="nofollow">orika</a>. But regardless of what I try i get this error <code>ma.glasnost.orika.MappingException: No concrete class mapping defined for source class org.joda.time.chrono.ISOChronology</code>. But it only fails on the jenkins server (unix), not locally (win).</p>

<p>The mapping from <code>DateMidnight</code> to <code>LocaleDate</code> is configured like this: </p>

<pre><code>public LocaleDate convert(DateMidnight source, Type&lt;? extends LocaleDate&gt; destinationType) {
    if (source == null) { return null; }
    return new LocaleDate(source);
}
</code></pre>

<p>Anyhow I've tried adding a concrete mappings between chronologies found in jodatime. </p>

<p>E.g </p>

<p><code>ISOChronology</code>-> <code>ISOChronology</code></p>

<p><code>ISOChronology</code> -> <code>Chronology</code></p>

<p><code>Chronology</code> -> <code>ISOChronology</code></p>

<p><code>Chronology</code> -> <code>Chronology</code></p>

<p>using the <code>registerClassMap</code> as shown below:</p>

<p><code>mapperFactory.registerClassMap(mapperFactory.classMap(ISOChronology.class, ISOChronology.class).byDefault().toClassMap());</code></p>

<p><code>ISOChronology</code> -> <code>ISOChronology</code> gives me <code>exception while creating object factory for org.joda.time.chrono.ISOChronology</code>.</p>

<p>Any help would be greatly appreciated</p>

<p><strong>EDIT - Solution and more infomation</strong></p>

<p>So, I found a solution after first registering a <code>ObjectFactory</code>for <code>Chronology</code> using <code>MapperFactory.registerObjectFactory</code>.</p>

<p>The code then failed with an exception explain how 280 was not a valid value for <code>hoursInDay</code> when creating a <code>LocaleDateTime</code>. Now, all mappers were set up to map from <code>DateMidnight</code> to <code>LocaleDate</code>, why would it try to initialize a <code>LocaleDateTIme</code> object... Below is the <code>Period</code> class it was trying to map to (written from memory)</p>

<pre><code>public class Period {
    public final LocaleDate from;
    public final LocaleDate to;

    public Period() {}//Rank: 0

    public Period(LocaleDate from, LocaleDate to) {//Rank: 2000
        this.from = from;
        this.to = to;
    }

    public Period(LocaleDateTime from, LocaleDateTime to) {//Rank: 2000
        this.from = from.toLocaleDate();
        this.to = to.toLocaleDate();
    }
}
</code></pre>

<p>The mapper from <code>XMLPeriod</code> to <code>Period</code> used <code>field("fom", "from")</code> and <code>field("to", "to")</code>.</p>

<p>Turns out Orika's constructor resolving strategy is based on a heuristic trying to find the constructor with the greatest number of arguments which it can fulfill. The heuristic does however not take into account which mappings or converters you have registered, and is purely looking at parameter-names. </p>

<p>Since the last two constructors have the same rank. It then ignores the constructor using <code>LocaleDate</code>, and tries to use initialize <code>LocaleDateTime</code>. And then fails brutally since it has no concept of the ordering of arguments for <code>LocaleDateTime</code> ( and would also fail because of <code>ISOChonology</code> being singleton-like, but that was fixed)</p>

<p><strong>So... The solution to all my problems...</strong></p>

<pre><code>//DONT change wtf name, orika-mappings will break.
public Period(LocaleDateTime from, LocaleDateTime wtf) {
    this.from = from.toLocaleDate();
    this.to = wtf.toLocaleDate();
}
</code></pre>

<p>Yeah, renaming a argument solved the problem... </p>

<p>PS. This probably isnt the best solution to this problem. But it is a solution. If anyone know how this can be solved in a better way, please let me know.</p>