title: Orika - map Page<T> to Page<TDto>
body: <p>I have a problem in mapping Page object to Page object.
  I have the following Mapper class:</p>
  
  <pre><code>package com.agileplayers.agilemanager.core.mapper;
  
  import com.agileplayers.agilemanager.core.domain.Account;
  import com.agileplayers.agilemanager.core.domain.Entry;
  import com.agileplayers.agilemanager.core.dto.AccountDto;
  import com.agileplayers.agilemanager.core.dto.EntryDto;
  import ma.glasnost.orika.MapperFacade;
  import ma.glasnost.orika.MapperFactory;
  import ma.glasnost.orika.impl.DefaultMapperFactory;
  import ma.glasnost.orika.metadata.TypeBuilder;
  import org.springframework.data.domain.PageImpl;
  import org.springframework.stereotype.Component;
  
  
  @Component
  public class Mapper {
      final static MapperFactory MAPPER_FACTORY = new DefaultMapperFactory.Builder().build();
  
      public MapperFacade getMapperFacade(){
          registerMappers();
          return MAPPER_FACTORY.getMapperFacade();
      }
  
      private void registerMappers(){
          MAPPER_FACTORY.classMap(Entry.class, EntryDto.class)
                  .byDefault()
                  .register();
  
          MAPPER_FACTORY.classMap(Account.class, AccountDto.class)
                  .byDefault()
                  .register();
          MAPPER_FACTORY.classMap(
                  new TypeBuilder&lt;PageImpl&lt;Entry&gt;&gt;() {}.build(),
                  new TypeBuilder&lt;PageImpl&lt;EntryDto&gt;&gt;() {}.build())
                  .byDefault()
                  .register();
  
      }
  }
  </code></pre>
  
  <p>which is used here:</p>
  
  <pre><code>@Autowired
      private EntryRepository entryRepository;
  
      private void start() {
          Mapper mapper = new Mapper();
          Page&lt;Entry&gt; entryPage = entryRepository.findAll(new PageRequest(0, 2));
  
          Type&lt;Page&lt;Entry&gt;&gt; pageEntryType = new TypeBuilder&lt;Page&lt;Entry&gt;&gt;() {
          }.build();
          Type&lt;Page&lt;EntryDto&gt;&gt; pageEntryDtoType = new TypeBuilder&lt;Page&lt;EntryDto&gt;&gt;() {
          }.build();
  
          Page&lt;EntryDto&gt; entryDtoPage = mapper.getMapperFacade().map(entryPage, pageEntryType, pageEntryDtoType);
  </code></pre>
  
  <p>unfortunately, I am receiving the following:</p>
  
  <pre><code>Exception in thread "main" ma.glasnost.orika.MappingException: While attempting the following mapping:
  sourceClass = class org.springframework.data.domain.PageImpl
  sourceType = org.springframework.data.domain.Page&lt;Entry&gt;
  destinationType = org.springframework.data.domain.Page&lt;EntryDto&gt;
  resolvedStrategy = InstantiateAndUseCustomMapperStrategy&lt;PageImpl&lt;Entry&gt;, PageImpl&lt;EntryDto&gt;&gt; {customMapper: GeneratedMapper&lt;PageImpl&lt;Entry&gt;, PageImpl&lt;EntryDto&gt;&gt; {usedConverters: [], usedMappers: [], usedMapperFacades: [DefaultBoundMapperFacade&lt;Sort, Sort&gt;], usedTypes: [Object] }, unenhancer: ma.glasnost.orika.unenhance.BaseUnenhancer@4b5aa48b, objectFactory: ma.glasnost.orika.generated.PageImpl_PageImpl_ObjectFactory59678627946495970211838179$3@2dd2ff87}
  Error occurred: java.lang.UnsupportedOperationException
  -----begin dump of current state-----------------------------
  Registered object factories: 3 (approximate size: 9,541.1 kB)
    [AccountDto] : {Account=DefaultConstructorObjectFactory&lt;AccountDto&gt;}
    [PageImpl&lt;EntryDto&gt;] : {PageImpl&lt;Entry&gt;=ma.glasnost.orika.generated.PageImpl_PageImpl_ObjectFactory59678627946495970211838179$3@2dd2ff87}
    [EntryDto] : {Entry=DefaultConstructorObjectFactory&lt;EntryDto&gt;}
  -------------------------------------------------------------
  Registered mappers: 3 (approximate size: 9,794.2 kB)
    [0] : GeneratedMapper&lt;PageImpl&lt;Entry&gt;, PageImpl&lt;EntryDto&gt;&gt; {usedConverters: [], usedMappers: [], usedMapperFacades: [DefaultBoundMapperFacade&lt;Sort, Sort&gt;], usedTypes: [Object] }
    [1] : GeneratedMapper&lt;Entry, EntryDto&gt; {usedConverters: [builtin:CloneableConverter(Copy by cloning:Date, Calendar, XMLGregorianCalendar)], usedMappers: [], usedMapperFacades: [DefaultBoundMapperFacade&lt;Account, AccountDto&gt;], usedTypes: [Date] }
    [2] : GeneratedMapper&lt;Account, AccountDto&gt; {usedConverters: [builtin:CloneableConverter(Copy by cloning:Date, Calendar, XMLGregorianCalendar)], usedMappers: [], usedMapperFacades: [], usedTypes: [Date, Entry, EntryDto] }
  -------------------------------------------------------------
  Registered concrete types: 6 (approximate size: 346.9 kB)
    [interface java.util.Collection] : ArrayList&lt;Object&gt;
    [interface java.util.Map] : LinkedHashMap&lt;Object, Object&gt;
    [interface java.util.Map$Entry] : MapEntry&lt;Object, Object&gt;
    [Page&lt;Entry&gt;] : PageImpl&lt;EntryDto&gt;
    [interface java.util.List] : ArrayList&lt;Object&gt;
    [interface java.util.Set] : LinkedHashSet&lt;Object&gt;
  -------------------------------------------------------------
  Resolved strategies: 4 (approximate size: 9,794.6 kB)
  {source: PageImpl, dest: Page&lt;EntryDto&gt;, in-place:false}: InstantiateAndUseCustomMapperStrategy&lt;PageImpl&lt;Entry&gt;, PageImpl&lt;EntryDto&gt;&gt; {customMapper: GeneratedMapper&lt;PageImpl&lt;Entry&gt;, PageImpl&lt;EntryDto&gt;&gt; {usedConverters: [], usedMappers: [], usedMapperFacades: [DefaultBoundMapperFacade&lt;Sort, Sort&gt;], usedTypes: [Object] }, unenhancer: ma.glasnost.orika.unenhance.BaseUnenhancer@4b5aa48b, objectFactory: ma.glasnost.orika.generated.PageImpl_PageImpl_ObjectFactory59678627946495970211838179$3@2dd2ff87}
  {source: Account, dest: AccountDto, in-place:false}: InstantiateAndUseCustomMapperStrategy&lt;Account, AccountDto&gt; {customMapper: GeneratedMapper&lt;Account, AccountDto&gt; {usedConverters: [builtin:CloneableConverter(Copy by cloning:Date, Calendar, XMLGregorianCalendar)], usedMappers: [], usedMapperFacades: [], usedTypes: [Date, Entry, EntryDto] }, unenhancer: ma.glasnost.orika.unenhance.BaseUnenhancer@4b5aa48b, objectFactory: DefaultConstructorObjectFactory&lt;AccountDto&gt;}
  {source: Entry, dest: Object, in-place:false}: InstantiateAndUseCustomMapperStrategy&lt;Entry, EntryDto&gt; {customMapper: GeneratedMapper&lt;Entry, EntryDto&gt; {usedConverters: [builtin:CloneableConverter(Copy by cloning:Date, Calendar, XMLGregorianCalendar)], usedMappers: [], usedMapperFacades: [DefaultBoundMapperFacade&lt;Account, AccountDto&gt;], usedTypes: [Date] }, unenhancer: ma.glasnost.orika.unenhance.BaseUnenhancer@4b5aa48b, objectFactory: DefaultConstructorObjectFactory&lt;EntryDto&gt;}
  {source: Entry, dest: EntryDto, in-place:false}: InstantiateAndUseCustomMapperStrategy&lt;Entry, EntryDto&gt; {customMapper: GeneratedMapper&lt;Entry, EntryDto&gt; {usedConverters: [builtin:CloneableConverter(Copy by cloning:Date, Calendar, XMLGregorianCalendar)], usedMappers: [], usedMapperFacades: [DefaultBoundMapperFacade&lt;Account, AccountDto&gt;], usedTypes: [Date] }, unenhancer: ma.glasnost.orika.unenhance.BaseUnenhancer@4b5aa48b, objectFactory: DefaultConstructorObjectFactory&lt;EntryDto&gt;}
  -------------------------------------------------------------
  Unenhance strategy: ma.glasnost.orika.unenhance.BaseUnenhancer@4b5aa48b
  -----end dump of current state-------------------------------
      at ma.glasnost.orika.impl.ExceptionUtility.newMappingException(ExceptionUtility.java:55)
      at ma.glasnost.orika.impl.MapperFacadeImpl.map(MapperFacadeImpl.java:280)
      at ma.glasnost.orika.impl.MapperFacadeImpl.map(MapperFacadeImpl.java:243)
      at ma.glasnost.orika.impl.MapperFacadeImpl.map(MapperFacadeImpl.java:133)
      at com.agileplayers.agilemanager.AgileManagerApplication.start(AgileManagerApplication.java:49)
      at com.agileplayers.agilemanager.AgileManagerApplication.main(AgileManagerApplication.java:34)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:498)
      at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)
  Caused by: java.lang.UnsupportedOperationException
      at java.util.Collections$UnmodifiableCollection.clear(Collections.java:1074)
      at ma.glasnost.orika.generated.Orika_PageImpl_PageImpl_Mapper5970055563717$0.mapAtoB(Orika_PageImpl_PageImpl_Mapper5970055563717$0.java)
      at ma.glasnost.orika.impl.mapping.strategy.UseCustomMapperStrategy.map(UseCustomMapperStrategy.java:67)
      at ma.glasnost.orika.impl.MapperFacadeImpl.map(MapperFacadeImpl.java:266)
      ... 9 more
  </code></pre>
  
  <p>There is no problem in mapping Entry to EntryDto or List to List. I assume the problem might be with parameterless constructor in PageImpl class but it is only my suspicion.
  Please advise, what I am doing wrong.</p>