Java ModelMapper - не удалось преобразовать java.util.List в java.util.List
Я использую библиотеку Java ModelMapper для сопоставления DTO с ORM @Entity
объекты. У меня установлен следующий тест:
public class MapperTest {
@Autowired
private ModelMapper mapper;
@Autowired
private TicketRepository ticketRepo;
@Test
public void testTicket() {
Ticket ticket = ticketRepo.findById(4).get();
TicketDTO dto = mapper.map(ticket, TicketDTO.class);
assertThat(dto.getEquipmenDescription()).isEqualTo(ticket.getEquipment().getDescription());
assertThat(dto.getEquipmentNotes()).isEqualTo(ticket.getEquipmentNotes());
assertThat(dto.getId()).isEqualTo(ticket.getId());
assertThat(dto.getNotes()).isEqualTo(ticket.getNotes());
assertThat(dto.getOracleID()).isEqualTo(ticket.getOracleID());
assertThat(dto.getPropertyID()).isEqualTo(ticket.getPropertyID());
assertThat(dto.getNotes().size()).isEqualTo(ticket.getNotes().size());
for (TicketNoteDTO note : dto.getNotes()) {
assertThat(note.getId()).isNotEqualTo(0);
assertThat(note.getIssueDate()).isNotNull();
assertThat(note.getUserUserName()).isNotEmpty();
}
}
}
Это терпит неудачу со следующей ошибкой:
org.modelmapper.MappingException: ModelMapper mapping errors:
1) Converter org.modelmapper.internal.converter.CollectionConverter@501c6dba failed to convert java.util.List to java.util.List.
Ниже приведены моя организация и соответствующие DTO. Геттеры и сеттеры для краткости опущены.
Билет
@Entity
@Table(name = "ticket")
public class Ticket {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
private int id;
@Column(name = "equipment_notes")
private String equipmentNotes;
@Column(name = "is_open")
private boolean isOpen;
@Column(name = "oracle_id")
private String oracleID;
@ManyToOne
@JoinColumn(name = "equipment_id")
private EquipmentCategory equipment;
@Column(name = "property_id")
private String propertyID;
@OneToMany(mappedBy = "ticket")
private List<TicketNote> notes = new ArrayList<>();
}
TicketNote (геттеры и сеттеры опущены для краткости)
@Entity
@Table(name = "ticket_note")
public class TicketNote {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
private int id;
@ManyToOne
@JoinColumn(name = "ticket_id")
private Ticket ticket;
@ManyToOne
@JoinColumn(name = "user_id")
private AppUser user;
@Column(name = "issue_date")
private LocalDate issueDate;
@Column(name = "oracle_contact")
private String oracleContact;
@Column(name = "issue_resolved")
private boolean issueResolved;
}
TicketDTO
public class TicketDTO {
private int id;
private String equipmentNotes;
private boolean isOpen;
private String oracleID;
private String equipmenDescription;
private String propertyID;
private List<TicketNoteDTO> notes = new ArrayList<>();
}
TicketNoteDTO
public class TicketNoteDTO {
private int id;
private String userUserName;
private LocalDate issueDate;
private String oracleContact;
private boolean issueResolved;
}
У меня есть некоторый опыт работы с библиотекой ModelMapper, но я не уверен, в чем проблема. Любой совет приветствуется.
Благодарю.