The Object Mapper pattern
What is object mapping? In a nutshell, it is the action of copying the value of an object’s properties into the properties of another object. But sometimes, properties’ names do not match; an object hierarchy may need to be flattened and transformed.
As we saw in the previous chapter, each layer can own its own model, which can be a good thing, but that comes at the price of copying objects from one layer to another. We can also share models between layers, but even then, we usually need to map one object onto another. Even if it’s just to map your models to Data Transfer Objects (DTOs), object mapping is almost inevitable.
Remember that DTOs define our API’s contract. Independent contract classes help maintain the system, making us choose when to modify them. If you skip using DTOs, each time you change your domain model, it automatically updates your endpoint’s contract, possibly breaking some clients....