I need to do a merge of objects in Java Spring Boot application (ProductDTO and Product).
ProductDTO does not contain all the fields from Product, and I would like to map only the fields that are the same in both objects, while preserving the other values in the destination object.
I am coming from the C# world, so I don't know what is the best way to achieve the same behavior in Java. In C# I would do it like this:
var project = new Project
{
Name = "Project 1",
Description = "Description"
};
var projectDto = new ProjectDTO
{
Name = "Project 1 (changed)"
};
Mapper.Map(projectDto, project);
After execution of the Map method, the project object still contains the original value for the Description field.
What is the best way to do this in Java Spring?