I have an object which contains several list. is there a method to clone this object without id using mapstruct even for the nested object list in an automatic way to be able to persist it.
@Data
public class ParentDto {
@Id
private Long id;
private String name;
private List<Child1Dto> children1;
private List<Child1Dto> children2;
}
@Data
public class Child1Dto {
@Id
private Long id;
private String name;
}
@Data
public class Child2Dto {
@Id
private Long id;
private String name;
}
Actual mapper
@Mapper(mappingControl = DeepClone.class)
public interface CloneParentMapper {
@Mapping(target = "id", ignore = true)
ParentDto cloneWithoutId(ParentDto parentDto );
@Mapping(target = "id", ignore = true)
Child1Dto cloneWithoutId(Child1Dto child1Dto );
@Mapping(target = "id", ignore = true)
Child2Dto cloneWithoutId(Child2Dto child2Dto );
}
is there a way to ignore all id without doing @Mapping(target = "id", ignore = true) on every list?
question from:
https://stackoverflow.com/questions/65876174/clone-object-without-ids-using-mapstruct 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…