I am trying to create a GRPC API where the payload can have custom contract per user. The user can define the contract by extending the base (fixed) contract up front (probably stored in a database) and start sending as per his custom contract.
I can define the base contract in the .proto file and generate the server and client classes at the compile time but is there any way I can enforce user defined contract at the time of de-serialization.
e.g.
BaseObject
- Id
- Date
UserObjectFoo
- Id
- Date
- userAttr1
UserObjectBar
- Id
- Date
- userAttr2
The definition of UserObjectFoo and UserObjectBar was provided after deployment so its not known to .proto.
Is there a way we could deserialize payload of type UserObjectFoo
and UserObjectBar
at the runtime after pulling out their definition from persistance.
Note: One rudimentary way is to have the custom fields like userAttr1 and userAttr2 as a key-value pair but it would have to be validated only after de-serialization into a Map by application logic, which could be an overhead.
i.e.
{
String id = 1
Date date = 2;
map<string, string> attributes = 3;
}