orika-mapper / orika

Simpler, better and faster Java bean mapping framework
http://orika-mapper.github.io/orika-docs/
Apache License 2.0
1.29k stars 268 forks source link

.exclude("xxx") not working in specific situation #304

Open SeliMeli opened 5 years ago

SeliMeli commented 5 years ago

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.