ModelMapper - 无法将 ArrayList 转换为列表

ModelMapper - Failed to convert ArrayList to List

我有以下 Bean

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 -> TicketDto 映射它,但当是 TicketDto -> Ticket 时它失败了。

非常感谢任何帮助。

有点傻,但 ORMLite 也接受 Collection 外国集合字段。所以:

public class Ticket extends BaseEntity {
    private Collection< TicketDetail > ticketDetails;
}