Extended a Serializable Class, how to use in Remote-Calls?
Here's my situation:
I have a server application, providing a remote interface which uses bean objects as call parameters / return values. These are of course Serializable. For instance, a Doctor, that works in a Surgery.
For my local application, i have extended these call objects: For instance, the doctor has an additional password field so the doctor's password can be stored locally. Now my local objects are also Serializable, and i also use this to send these around through the local network.
What is the easiest way for me now, to use objects of my extended implementations in a remote call to the server? The server obviously can't reconstruct my serialized implementations, because he doesn't know my specialize开发者_开发问答d classes.
Do i have to manually create a un-extended bean object from my extended one by basically copying all the fields except the new ones? or is there a better/easier way to do this? Overwriting the serialization methods is not an option because, as i stated above, i still need my local objects to be normally Serializable too.
The server obviously can't reconstruct my serialized implementations, because he doesn't know my specialized classes.
Unless your server can get to know about your specialized classes via a jar in the classpath, you won't be able to have it unserialize your classes.
Creating proxies could be an angle to explore, but with no guarantee this would work (not enough details about your specific situation).
An easier solution is to use a root class for your beans, containing or extending a hash map and store the properties/values in it. Instead of creating getter and setter for each property, implement only one pair and provide the property name as a string.
The server won't have any issue to unserialize it, unless one of the Serializable object in the map is unknown to the server. This method allows you to add any extra bean information in it and the server will always know how to deal with it.
There is also a trickier angle you could try. The class Class is serializable by itself. Therefore, if you transferred it before you transfer your beans, may be the server could learn about it first. I have never tried this myself, so I don't know if it would work. Just an idea.
精彩评论