Home > Enterprise >  ModelMapper does not work with multiple IDs
ModelMapper does not work with multiple IDs

Time:01-08

I'm trying to convert one object to another using ModelMapper and it's not working when submitting with multiple ids, the following implementations:

ModelMapper Config:

enter image description here

ScheduleRequest:

enter image description here

Schedule:

enter image description here

ScheduleMapper:

enter image description here

ScheduleController:

enter image description here

Request POSTMAN:

enter image description here

Final result:

enter image description here

CodePudding user response:

solved manually, but in a non-elegant way:

enter image description here

CodePudding user response:

It's not the problem with multiple IDs, it's about you have different data types. In ScheduleRequest, there are personId and examId with Long type, however in the Schedule entity object, there are person and exam fileds with Person and Exam type accordingly. ModelMapper works fine in this case.

Your solution is correct. But take care, if you set some kind of cascading for Person and Exam entities (CascadeType.MERGE), you will end up in data-loss! (Based on the class names and relations you will not set cascading :) )

  •  Tags:  
  • Related