I have a usecase where I am supposed to store entire payload from a third party API in addition to the DTO, say XYZDto, its translated to.
There are two ways to achieve that -
Translate the payload into DTO as it is and when it comes to converting it into corresponding entity, I would do
entity.apiPayload = convertToJson(dto)
Another way is to have to have a payload field in dto itself and write my own mapper which does the following.
a. Perform the usual payload to DTO conversion
b. Store the payload in DTO
dto.apiPayload = payloadThis way payload will already be ready while converting to entity and we will just do
entity.apiPayload = dto.apiPayload
As I understand, advantage of Option 2 is there will not be unnecessary translation of dto back to payload at runtime.
I want to understand if there is a design pattern or rule that I am breaking here. Am I missing any trade-offs between DTO strictly having the same structure as its payload vs. having a different structure?