我有以下豆子
public class Ticket extends BaseEntity {
private ForeignCollection< TicketDetail > ticketDetails;
}
public class TicketDto extends BaseDto {
private List< TicketDetailDto > ticketDetails;
}
我使用ModelMapper进行映射,List<TicketDto>
到List<Ticket>
就好了
List<TEntity> entities = mapper.map( dtoList, new TypeToken<List<Ticket>>(){}.getType() );
但它抛出以下异常和Stacktrace
1) Converter org.modelmapper.internal.converter.CollectionConverter@5d884430 failed to convert java.util.ArrayList to java.util.ArrayList.
1 error
at org.modelmapper.internal.Errors.throwMappingExceptionIfErrorsExist(Errors.java:374)
at org.modelmapper.internal.MappingEngineImpl.map(MappingEngineImpl.java:69)
at org.modelmapper.ModelMapper.mapInternal(ModelMapper.java:497)
at org.modelmapper.ModelMapper.map(ModelMapper.java:429)
Caused by: org.modelmapper.MappingException: ModelMapper mapping errors:
1) Failed to set value '' on com.pichardo.metalesbc.infrastructure.domainentities.Ticket.setTicketDetails()
1 error
at org.modelmapper.internal.Errors.toMappingException(Errors.java:258)
at org.modelmapper.internal.PropertyInfoImpl$MethodMutator.setValue(PropertyInfoImpl.java:118)
at org.modelmapper.internal.MappingEngineImpl.setDestinationValue(MappingEngineImpl.java:250)
at org.modelmapper.internal.MappingEngineImpl.propertyMap(MappingEngineImpl.java:181)
at org.modelmapper.internal.MappingEngineImpl.typeMap(MappingEngineImpl.java:132)
at org.modelmapper.internal.MappingEngineImpl.map(MappingEngineImpl.java:101)
at org.modelmapper.internal.converter.IterableConverter.convert(IterableConverter.java:49)
at org.modelmapper.internal.MappingEngineImpl.convert(MappingEngineImpl.java:337)
at org.modelmapper.internal.MappingEngineImpl.map(MappingEngineImpl.java:96)
at org.modelmapper.internal.MappingEngineImpl.map(MappingEngineImpl.java:60)
... 50 more
Caused by: java.lang.IllegalArgumentException: argument type mismatch
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:497)
at org.modelmapper.internal.PropertyInfoImpl$MethodMutator.setValue(PropertyInfoImpl.java:116)
它似乎从Ticket - &gt;正确映射TicketDto但是在TicketDto - >时失败了票。
非常感谢任何帮助。
答案 0 :(得分:1)
有点愚蠢,但ORMLite也接受Collection
外国收集字段。所以:
public class Ticket extends BaseEntity {
private Collection< TicketDetail > ticketDetails;
}