I have Entity (Course) and DTO (CourseDto) with spring boot as API server, backend as mongo
@Document(collection = "courses")
public class Course {
@Id private ObjectId id;
....
}
public class CourseDto {
private String id;
....
}
I am using modelmapper to convert from CourseDto to Course and vise-versa. From Course id (ObjectId) to CourseDto id (String) conversion happens correctly (similar to course.getId().toHexString()). It gives me hexstring. But when I try to convert from CourseDto to Course (String id to ObjectId) then completely new ObjectId gets generated.
I know I can use converter but this is applicable thought out all my 50+ entity classes + also for deep nested objects. E.g. Course contains list of topics and each topic contains list of article Ids (List of ObjectId). According to my knowledge I can attach converted to specific model mapper (in this case to course model mapper)
I am mainly looking for generic solution where proper conversion from String to ObjectId would happen (new ObjectId(myString) ) and new ObjectId will not get created.
Thanks in advance