We are using Golang to implement a REST API which including CRUD, in Update service, client could send partial JSON including changed fields, and we need to handle for updating entity with these changes.
Logically, we need to get entity by Id from DB to struct, and then unmarshal payload json to another struct and update entity.
However if payload json is not fully, for example I have struct
type Customer struct {
Id int64 `json:"id"`
Name string `json:"name"`
Age int `json:"age"`
}
And JSON request looks like
{
"Name": "Updated name"
}
Then the customer should be updated with new name.
That's simple example, actually it could be a nested struct and nested json, how could we handle that case with golang, or event other language like Java, .NET