简体   繁体   English

Java Serializable对象包含不可序列化的字段

[英]Java Serializable object contains non-Serializable fields

I use FindBugs in eclipse, and there are tons of "troubling" warnings. 我在Eclipse中使用FindBugs,并且有很多“麻烦”警告。
Here is the sketch code: 这是草图代码:

public class SerializableObject implements Serializable {

  private NonSerializableObject nso;

  .. setter, getter, everything else

}

Can this cause troubles? 这会引起麻烦吗? Or can we just ignore it? 还是我们可以忽略它? Or should we do the Serialization everywhere it touches? 还是我们应该在涉及到的地方进行序列化?

It is in a JSF Web project. 它在JSF Web项目中。

You have to mark them as transient 您必须将它们标记为transient

When you declare a field transient it will be ignored during the serialization and deserialization process. 声明字段瞬态时,在序列化和反序列化过程中将忽略该字段。 Keep in mind that when you deserialize an object with a transient field that field's value will always be it's default (usually null.) 请记住,当使用瞬态字段反序列化对象时,该字段的值将始终为默认值(通常为null)。

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

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