Started working on java spring boot for a project requirement I want to understand what is the best way to use ModelMapper for my scenario.
I have a model InputMsg:
public class InputMsg {
String EquipmentNumber;
//getters setters
}
Further, I have two DTOs OutputMsg and ErrorDesc
public class OutputMsg {
public ErrorDesc EquipmentNumber;
//getters setters
}
public class ErrorDesc {
String Value;
//getters setters
}
My requirement is to use the incoming input message and finally return a result in the OutputMsg format which I can further take to do some other calculations.
eg. InputMsg -- "ABCD1234" OutputMsg : EquipmentNumber.value = "ABCD1234"
What I have used is something like this with ModelMapper is :
ModelMapper modelMapper = new ModelMapper();
PropertyMap <InputMsg, OutputMsg> orderMap =
new PropertyMap <InputMsg,OutputMsg>() {
protected void configure() {
OutputMsg.getEquipmentNumber()
.setValue(InputMsg.getEquipmentNumber());
}
modelMapper.addMappings(orderMap);
return OutputMsg;
}};
The Problem I see is if I have 100's of property i will have to write a 100 lines of code to map it.
How can i do it in a better way to automatically map the InputMsg value to Output.Msg
Help is appreciated Regards