Generic Class in COS
Hello everyone,
I'm doing a REST service for integration between 2 systems. The system that invokes me expects a response object where only one of its attributes changes. It could be something like this:
Class ResponseCustomer { Property Code As %String; Property Info As Customer; }
Class ResponseAppointment { Property Code As %String; Property Info As Appointment; }
Class ResponseCancellation { Property Code As %String; Property Info As %String; }
To avoid creating almost identical objects for each of the methods of my REST service, I had thought to implement it with generic classes known in other languages like .NET or JAVA that allow to be able to define at run time the type of that parameter. In addition, that response must be able to be transformed into JSON. I imagine something like this (in pseudo code / COS / .NET):
Class Response <T> { Property Code As %String; Property Info As T; }
// Create an answer to create a new Customer Set responseCustomer = ## class (Response <Customer>). New () // Create an answer to reserve a room Set responseAppointment = ## class (Response <Appointment>).% New () // Create an answer to cancel a reservation Set responseCancelation = ## class (Response <String>).% New ()
Is this possible in COS?. I haven't found a similar question about this in the community.
My attempts have been with the use of %Library.DynamicObject but when creating the JSON, the dynamic part isn't serialized.
Thanks