I'm building a microservice system with multiple disconnected components, and I'm currently trying to find out how to implement knowing which fields on an object should be updated based on the protobuf
data provided.
The flow is this:
- The client sends a JSON-request to an API.
- The API translates the JSON-data into a
protobuf
struct, which is then sent along to the microservice responsible for handling it. - The microservice receives the data from the API and performs any action on it, in this case, I'm trying to change a single value in a MySQL table, such as a client's email address.
Now, the problem I have is that since protobuf
(understandably) doesn't allow pointers, the protobuf
object will contain zero-values for everything not provided. This means that if a customer wants to update their email address, I can't know if they also set IncludeInMailLists
to false
- or if it was simply not provided (having its zero-value) and shouldn't change.
The question is: how will I - from the protobuf object - know if a value is expressively set to 0, or just not provided?
My current solution is pretty much having a special UpdateCustomer
-object which also has an array of Fields
specifying which fields the microservice should care about, but it feels like bad solution.
Someone must have solved this better already. How should I implement it?