简体   繁体   中英

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). 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.

This is usually done using static code analysis.

One tool that's used a lot is 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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