Should Class objects be serialized?

蓝咒 提交于 2019-12-23 15:16:05

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!