404-not-find / orika

Automatically exported from code.google.com/p/orika
2 stars 0 forks source link

Orika tries generates mapper for private field #173

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
0. mapping Dto -> entity 
1. only one CustomMapper<Date, LocalDateTime>
2. Dto class contains: public LocalDateTime createdDate
3. Entity class contains: protected Date createdDate; public Date 
getCreatedDate(); w/o setter

What is the expected output? What do you see instead?
-> expected: 
Field(createdDate(LocalDateTime), createdDate(Date)) : excluding because 
Entity.createdDate(Date) is not assignable and cannot be mapped in-place

-> actual: 
Field(createdDate(LocalDateTime), createdDate(Date)) : mapping object to object
and
Error occurred: ma.glasnost.orika.MappingException: Encountered mapping of 
primitive to object (or vise-versa); sourceType=Month, destinationType=int

What version of the product are you using? On what operating system?
1.4.5 oracle java 8-05 Mac Os X 10.9

Please provide any additional information below.
there in an interested place in source code 
https://github.com/orika-mapper/orika/blob/master/core/src/main/java/ma/glasnost
/orika/impl/generator/MapperGenerator.java#L233

Why destination property without setter should be immutable: 
ClassUtil.isImmutable(destinationProperty.type())) ?

If I right understood, an additional mapper CustomMapper<LocalDateTime,Date> 
solves the exception problem but field mapping still generated

Original issue reported on code.google.com by Malyhi...@gmail.com on 5 Sep 2014 at 8:49

GoogleCodeExporter commented 8 years ago
Can you please attach a simple test case for the issue, so I can look at this 
quickly.

Original comment by elaat...@gmail.com on 5 Sep 2014 at 9:48

GoogleCodeExporter commented 8 years ago
I've attached a test class but this test doesn't throw exceptions
mapping still here:
Field(createdDate(LocalDateTime), createdDate(Date)) : mapping object to object
but I don't see mapping generation. 

My program have similar behavior and orika tries create LocalDateTime -> Date 
mapping

05.09.14 13:44:39 [main] [] DEBUG m.g.orika.impl.DefaultMapperFactory - No 
mapper registered for (Dto, Entity): attempting to generate
05.09.14 13:44:39 [main] [] DEBUG m.g.orika.metadata.ClassMapBuilder - ClassMap 
created:
    ClassMapBuilder.map(Dto, Entity)
     .field( id(Long), id(Long) )
     .field( name(String), name(String) )
     .field( createdDate(LocalDateTime), createdDate(Date) )
     .field( visible(Boolean), visible(Boolean) )
05.09.14 13:44:39 [main] [] DEBUG m.g.o.impl.generator.MapperGenerator - 
Generating new mapper for (Dto, Entity)
    Orika_Entity_Dto_Mapper1409924679235244000$15.mapAToB(Dto, Entity) {
     Field(id(Long), id(Long)) : excluding because Entity.id(Long) is not assignable and cannot be mapped in-place
     Field(name(String), name(String)) : copying String by reference
     Field(createdDate(LocalDateTime), createdDate(Date)) : mapping object to object
     Field(visible(Boolean), visible(Boolean)) : copying Boolean by reference
    }
    Orika_Entity_Dto_Mapper1409924679235244000$15.mapBToA(Entity, Dto) {
     Field(id(Long), id(Long)) : copying Long by reference
     Field(name(String), name(String)) : copying String by reference
     Field(createdDate(Date), createdDate(LocalDateTime)) : converting using CustomConverter(DateToLocalDateTimeConverter)<Date, LocalDateTime>
     Field(visible(Boolean), visible(Boolean)) : copying Boolean by reference
    }
    Types used: [LocalDateTime]
    Converters used: [CustomConverter(DateToLocalDateTimeConverter)<Date, LocalDateTime>]
    BoundMapperFacades used: [DefaultBoundMapperFacade<LocalDateTime, Date>]
05.09.14 13:44:39 [main] [] DEBUG m.g.orika.impl.MapperFacadeImpl - 
MappingStrategy resolved and cached:
    Inputs:[ sourceClass: app.core.Dto, sourceType: null, destinationType: class app.domain.Entity]
    Resolved:[ strategy: MapExistingAndUseCustomMapperStrategy, sourceType: Dto, destinationType: Entity, mapper: GeneratedMapper<Dto, Entity> {usedConverters: [CustomConverter(DateToLocalDateTimeConverter)<Date, LocalDateTime>], usedMappers: [], usedMapperFacades: [DefaultBoundMapperFacade<LocalDateTime, Date>], usedTypes: [LocalDateTime] }, mapReverse?: false]
05.09.14 13:44:39 [main] [] DEBUG m.g.orika.impl.DefaultMapperFactory - No 
mapper registered for (LocalDateTime, Date): attempting to generate
05.09.14 13:44:39 [main] [] DEBUG m.g.orika.metadata.ClassMapBuilder - ClassMap 
created:
    ClassMapBuilder.map(LocalDateTime, Date)
     .field( month(Month), month(int) )
     .field( year(int), year(int) )
05.09.14 13:44:39 [main] [] DEBUG m.g.o.i.g.s.PrimitiveAndObject - 
PrimitiveAndObject condition occurred; context: 
src: month(Month)
src.isArrayElement: false
src.isListElement: false
src.isMapKey: false
dest: month(int)
dest.isArrayElement: false
dest.isListElement: false
dest.isMapKey: false
05.09.14 13:44:39 [main] [] DEBUG m.g.o.impl.generator.MapperGenerator - 
Generating new mapper for (LocalDateTime, Date)
    Orika_Date_LocalDateTime_Mapper1409924679276935000$16.mapAToB(LocalDateTime, Date) {
<---- ERROR occurred here

ma.glasnost.orika.MappingException: While attempting the following mapping:
sourceType = java.time.LocalDateTime
destinationType = java.util.Date
Error occurred: ma.glasnost.orika.MappingException: While attempting the 
following mapping:
sourceType = java.time.LocalDateTime
sourceProperty = month(Month)
destinationType = java.util.Date
destinationProperty = month(int)
Error occurred: ma.glasnost.orika.MappingException: Encountered mapping of 
primitive to object (or vise-versa); sourceType=Month, destinationType=int

If you have any suggestions why orika may to do that, please let me know. 
As I wrote additional custom mapper LocalDateTime > Date solves the problem, I 
hope there is a better way :)

Original comment by Malyhi...@gmail.com on 5 Sep 2014 at 2:04

Attachments: