title: Custom Mapping with orika
body: <p>I am using Orika Mapper for mapping my fields of source and destination class.</p>
  
  <p>I can do one-to-one mapping perfectly.</p>
  
  <p>I have two fields like dateOfDeparture and dateOfArrival in Source class.</p>
  
  <p>I have to calculate difference between these dates and map to a field "travelDuration" in destination class.</p>
  
  <p>Following is the mapper class.</p>
  
  <pre><code>package com.tcs.Orika;
  
  import java.text.ParseException;
  import java.text.SimpleDateFormat;
  import java.util.Date;
  import java.util.HashMap;
  import java.util.Map;
  import java.util.concurrent.TimeUnit;
  
  import ma.glasnost.orika.MapperFacade;
  import ma.glasnost.orika.MapperFactory;
  import ma.glasnost.orika.converter.ConverterFactory;
  import ma.glasnost.orika.impl.ConfigurableMapper;
  import ma.glasnost.orika.impl.DefaultMapperFactory;
  
  public class Mapper extends ConfigurableMapper {      
        public static void main(String[] args) throws ParseException {
  
            /*Date Calculation*/
            SimpleDateFormat dateFormat = new SimpleDateFormat("dd-M-yyyy hh:mm:ss");
            String dateOfDeparture = "31-08-1982 10:20:56";
            String dateOfArrival = "31-08-1983 10:20:56";         
            Date date1 = dateFormat.parse(dateOfDeparture);
            Date date2 = dateFormat.parse(dateOfArrival);
            long diff = date2.getTime() - date1.getTime();
            int noOfDays = (int) TimeUnit.DAYS.convert(diff, TimeUnit.MILLISECONDS);
  
            /*set values to Source object*/
            OrikaMapFrom objectMapFrom  = new OrikaMapFrom();
            OrikaMapTo objectMapTo = new OrikaMapTo();
            objectMapFrom.setSource("Delhi"); 
            objectMapFrom.setDestination("Amsterdam");
            objectMapFrom.setDateOfDeparture(date1);
            objectMapFrom.setDateOfArrival(date2);
  
            /*Name Mapping when source and destination names are different*/
            MapperFactory mapperFactory = new DefaultMapperFactory.Builder().build(); 
            mapperFactory.classMap(OrikaMapFrom.class, OrikaMapTo.class)
              .field("source", "sourcePlace")
              .field("destination","destinationPlace")
              .field(noOfDays,"travelDuration")---------------&gt;facing error on this line
              .register();
  
            /*Value Mapping*/  
            MapperFacade mapper = mapperFactory.getMapperFacade();
            objectMapTo = mapper.map(objectMapFrom, OrikaMapTo.class);
            objectMapTo.setTravelDuration(noOfDays);
  
              System.out.println(objectMapTo.getSourcePlace());
              System.out.println(objectMapTo.getDestinationPlace());
              System.exit(0); 
          }
  
  
  
      }
  </code></pre>
  
  <p>please Advice how to map (noOfDays,"travelDuration").</p>