If I have a Class ProfessorDto and a Class StudentDto how can I avoid circular issues if the ProfessorDto have a list of StudentDto and the StudentDto have a property of type ProfessorDto ? I didn't put the code of the domain class but let's say it is the same as for the Dto.
I'm new to Mapstruct, converting a domain bean to a Dto with simple properties like Long, String is working but in my exemple, the relation OneToMany is not working !
@JsonApiResource(type = "professor")
@NoArgsConstructor
@Data
public class ProfessorDto {
@JsonApiId
private Long id;
private String professorName;
@JsonApiRelation(mappedBy = "professor")
private List<StudentDto> student;
public ProfessorDto(Long id) {
this.id = id;
}
}
And a class Student
@JsonApiResource(type = "student")
@NoArgsConstructor
@Data
public class StudentDto {
@JsonApiId
private Long id;
private String studentName;
@JsonApiRelation
private ProfessorDto professor;
}
My Mapper for Professor is
@Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE)
public interface ProfessorMapper {
ProfessorDto domainToDto(Professor domain);
Professor dtoToDomain(ProfessorDto dto);
StudentDto studentToDto(Student student);
Student studentDtoToDomain(StudentDto studentDto);
List<StudentDto> studentToDto(List<Student> student);
List<Student> studentDtoToDomain(List<StudentDto> studentDto);
}