1
votes

Is the conversation interface you can inject in a @ConversationScoped bean safe to mark transient (ie. will CDI deal with it is during serialization) or I do I need a custom read/writeObject?

@ConversationScoped
    public class CDIConversationScopedBean implements Serializable {
        private static final long serialVersionUID = 1L;
        @Inject
        private transient Conversation conversation; // <<-- transient ok?

FindBugs is complaining about a non-transient non-serializable instance field.

1

1 Answers

0
votes

TL;DR: Yes, it is safe. Explanation:

Since the Conversation class doesn't implement the Serializable interface as well the static analyzers usually complain that all the fields must be either Serializable or transient even if the class is never explicitly serialized or deserialized.

Firstly, your snippet is a bit questionable, why do you implement this marker interface - so do you plan to serialize this class? You might want to add the generated or default Serial Version UID.

To solve this, make the field transient if you don't plan to make de/serialize the class - it's harmless and will not affect the behavior of Conversation. See Java 8 specification, chapter 8.3.1.3.

Variables may be marked transient to indicate that they are not part of the persistent state of an object.

If you plan, make Conversation implement Serializable and treat its fields in the same way.