简体   繁体   English

序列化检查-编译时间和运行时

[英]serialization check - compile time and runtime

i am looking for a tool, that can tell me whether a class / object is legal serializeable object (implements serializable, and all its fields are serializable). 我正在寻找一种工具,该工具可以告诉我类/对象是否为合法的可序列化对象(实现可序列化,并且其所有字段均可序列化)。 i know that i can know whether an object is serializable only on run time. 我知道我可以知道对象是否只能在运行时才能序列化。 i want to get warning on compile time, whether a class can be not serializable (eg - a member is not serializeable, although in runtime it can be null, or of seriazliable sub class type). 我想在编译时警告类是否不能序列化(例如-成员不可序列化,尽管在运行时它可以为null或可序列化的子类类型)。 in addition, on runtime i want to check if a class is really serializable, before trying to send it over the network as a serialized object. 另外,在运行时,我想检查一个类是否真的可序列化,然后再尝试通过网络将其作为序列化对象发送。

thanks... 谢谢...

Does it have to be compile time? 一定要编译时间吗? I've done this with unit tests before, which is pretty close to compile time in terms of development lifecycle. 之前,我已经通过单元测试完成了这一点,就开发生命周期而言,这与编译时间非常接近。 This article is a bit dated but outlines a few good approaches. 本文有些过时,但概述了一些好的方法。 We also caught unserializable state by doing a true failover test for our webapp using two web servers, which is why I needed to verify serializability. 我们还通过使用两个Web服务器对我们的Web应用程序进行了真正的故障转移测试,从而捕获了无法序列化的状态,这就是为什么我需要验证可序列化性的原因。

This is usually done using static code analysis. 通常使用静态代码分析完成此操作。

One tool that's used a lot is Findbugs . 一种经常使用的工具是Findbugs It will tell you about many common problems and suspect behaviour. 它会告诉您许多常见问题和可疑行为。 One of its checks is the one you mention (described here) . 它提到的一项检查是您提到的一项(在此描述)

There are plugins for most IDEs for this, so it can do its job while you work, and a common pattern is to include this in your automatic build. 大多数IDE都有用于此目的的插件,因此它可以在工作时完成其工作,一种常见的模式是将其包括在自动构建中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM