First a solution followed by an explanation:
The easiest way is to mark the InfoPageMapper mapper field in InfoPageController as transient :
@Named @SessionScoped public class InfoPageController implements Serializable { @Inject transient private InfoPageMapper mapper;
And now the explanation:
The error message states this in a readable language:
The bean InfoPageController, which is a SessionScoped, must be serializable, but this requires an InfoPageMapper that is not serializable or transient β it is not possible to determine how to serialize the InfoPageController.
There are several areas in CDI (most often SessionScope) that require beans to be Serializable - mainly because they are somehow related to an HTTP session, which may contain more objects that fit into memory and from time to time a server may be required replace them with a disk.
It seems you got this because InfoPageController implements Serializable. But this is not enough in accordance with the principles of Java serialization. You must make sure that all the fields of the members of your Serializable class are one of the following: - a primitive type (int, boolean) - an object that is serialized (all serialization rules are applied recursively) - the field is marked with the keyword transient (which is located at the same level as the private keyword)
The trick with CDI is that you can mark all entered fields as transient, because they are re-entered when the object is deserialized from disk to memory. Therefore, you will not lose the transition object, which otherwise would have been null during deserialization, since it had not previously been saved to disk.
Another solution is to create a serializable embeddable bean InfoPageMapper. But then the problem can recurs recursively with the fields entered in InfoPageMapper. The Transient keyword solves your problem when this happens, and does not cause other benas to be serializable if they don't need to.
source share