问题
We have a distributed application, and our "managed" nodes have to sent information about "features" to the controller node. Our first approach was to simply send instances of some Map<Class, FeatureSet>
. ( the FeatureSet
class for valus can be ignored in the context of my question )
Now a coworker suggested in a review to avoid serializing instances of java.lang.Class
, mainly for potential version incompatibility issues: over time, our controller nodes are replaced with newer systems, whereas the "managed" nodes stay put. This means that a controller node might be running Java 12, 13, xx in a few years, receiving serialized map objects, generated by a Java 8 JVM.
I assume that this shouldn't lead to issues (hoping that the people releasing the JVMs avoid incompatible changes for such core classes), but still I am wondering if there are good technical reasons to not serialize instances of java.lang.Class
given the above requirements.
In other words: are the benefits from changing the map key type to String
for example (in that case, we could simply use clazz.getCanonicalName()
as key, instead of some clazz
object)?
来源:https://stackoverflow.com/questions/50162293/should-class-objects-be-serialized