2

我有以下豆子

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 时它失败了。

任何帮助是极大的赞赏。

4

1 回答 1

1

有点愚蠢,但它 ORMLite 也接受Collection外国收集字段。所以:

public class Ticket extends BaseEntity {
    private Collection< TicketDetail > ticketDetails;
}
于 2017-01-19T15:13:41.620 回答