Should I declare injected variables as transient
in Java EE?
I am getting a FindBugs warning:
Class com.playaround.HelloServlet defines non-transient non-serializable instance field accelerationUnit
This Serializable class defines a non-primitive instance field which is neither transient, Serializable, or java.lang.Object, and does not appear to implement the Externalizable interface or the readObject() and writeObject() methods.
Objects of this class will not be deserialized correctly if a non-Serializable object is stored in this field.
The code in play is:
/**
* Sample of a web service reference.
*/
@WebServiceRef
private AccelerationUnit accelerationUnit;
Same question applies to @Resource
, @Inject
, @PersistenceUnit
etc.