Custom widget how to pass data where type is not known in advance

I have created a custom widget where I need to pass data from the server to the client thru the SharedState where the type of the property could be a String, Integer or a custom Range object. The only way I figured out how to do this was to create a wrapper object where I have a setter which stores a value for the type of the object and then a field for each type and then a getter which will return the correct value depending on the type that was stored. I know this is probably not the right way, so would like advice on how to do it correctly.

In addition, in the other direction (rpc from client to server) I want to send data back whose type can vary. Is there a way to do this or do I need a different rpc call to the server for every possible type I need to send back?

Thanks in advance for specific help. I am a beginner and you can never spell it out too clearly for the likes of me.