I have a problem with Orika 1.4.5 and PermGen Space.
Indeed, i'm using a a ConfigurableMapper this way :
public class SoapSearchPrdvFreeSlotsMapper extends ConfigurableMapper {
@Override
public void configure(MapperFactory mapperFactory) {
mapperFactory.registerClassMap(mapperFactory.classMap(PrdvFreeSlot.class, PrdvWsListerDispoTelV2Filter.class)
.field("typeRdv", "wsldtTypeRdv")
.field("motifId", "wsldtMotifId")
.byDefault().toClassMap());
}
mapperFactory.registerClassMap(mapperFactory.classMap(PrdvFreeSlot.class, PrdvWsListerDispoTelV2.class)
.field("typeRdv", "wsldtTypeRdv")
.field("motifId", "wsldtMotifId")
.field("quantum", "wsldtActiviteIdActivQuantum")
.field("activiteJours", "wsldtActiviteIdActivJours")
.field("activiteHeureFerme", "wsldtActiviteIdActivHeureFerme")
.field("activiteHeureOuvert", "wsldtActiviteIdActivHeureOuvert")
.field("startDate", "disDate")
.field("disCapacity", "disCapacite")
.field("disReserve", "disReserve")
.field("reserveCC", "wsldtReserveCC")
.byDefault().toClassMap());
}
}
@Override
public void configureFactoryBuilder(DefaultMapperFactory.Builder builder) {
builder.build().getConverterFactory().registerConverter(new DateXmlDateConverter());
}
}
But each time i call this mapper, i have autogenerated class mappers which are stored in the PermGen.
I try to use the "existsRegisteredMapper" of the MapperFactory to prevent class mappers auto-generation but it doesn't work:
public static <T, U> boolean existsRegisteredMapperInFactory(MapperFactory mapperFactory, Class<T> classSrc, Class<U> classDest) {
return mapperFactory.existsRegisteredMapper(TypeFactory.valueOf(classSrc), TypeFactory.valueOf(classDest), true);
}
and the modified first code block:
if (!existsRegisteredMapperInFactory(mapperFactory, PrdvWsListerDispoTelV2Filter.class, PrdvFreeSlot.class)) {
mapperFactory.registerClassMap(mapperFactory.classMap(PrdvFreeSlot.class, PrdvWsListerDispoTelV2Filter.class)
.field("typeRdv", "wsldtTypeRdv")
.field("motifId", "wsldtMotifId")
.byDefault().toClassMap());
}
Please, Is there a way to prevent class mappers autogeneration without rewriting all the mappers i have ?
Thanks for your help.
Please make sure that the mapper is a singleton. You don't need to instantiate it everytime.
You don't need to verify if the the mapper has been registered or not. It will be generated only once (per MapperFactory instance).
So just make sure that SoapSearchPrdvFreeSlotsMapper is a singleton (only one instance, ConfigurableMapper is thread-safe)