Assume source class A and destination class B are like:
public class A {
private String id;
private String birthDate;
// and public getter and setter
}
public class B {
private String id;
private LocalDateTime birthDate;
// and public getter and setter
}
And the MapperFactory configure is like:
MapperFactory mapperFactory = new DefaultMapperFactory.Builder().build();
mapperFactory.classMap(A.class,B.class)
.exclude("birthDate").byDefault()
.register();
When using mapperFacade like:
MapperFacade mapperFacade = mapperFactory.getMapperFacade();
A a = //a not empty A instance
mapperFacade.map(a, B.class);
An exception will arise:
ma.glasnost.orika.MappingException: While attempting the following mapping:
sourceType = java.lang.String
destinationType = java.time.LocalDateTime
But when using map(S sourceObject, D destinationObject) instead of map(S sourceObject, Class<D> destinationClass), the code above works just fine without any error or exception and gives a correct result whose id field is mapped from a instance and birthDate field is still null.
And after replace the LocalDateTime with any other type that orika can not map from a string(a static util class for example), map(a, B.class) works.
Assume source class A and destination class B are like:
And the MapperFactory configure is like:
When using mapperFacade like:
An exception will arise:
But when using
map(S sourceObject, D destinationObject)
instead ofmap(S sourceObject, Class<D> destinationClass)
, the code above works just fine without any error or exception and gives a correct result whoseid
field is mapped froma
instance andbirthDate
field is still null.And after replace the
LocalDateTime
with any other type that orika can not map from a string(a static util class for example),map(a, B.class)
works.