I can't understand how serialization works in session scoped JSF managed beans. Why is implementation of Serializable
interface important while creating a session scoped JSF managed bean?
相关问题
- java.lang.NullPointerException at java.io.PrintWri
- Json.NET deserializing contents of a JObject?
- h:selectOneMenu in p:dataTable doesn't submit
- Data loss during sending via $_SESSION from one sc
- PrimeFaces block UI does not work when the compone
相关文章
- Page指令 的EnableSessionState="ReadOnly",怎么在web.confi
- serializing a list of objects into a file in java
- Convert C# Object to Json Object
- How exactly do Firebase Analytics handle session d
- When sending XML to JMS should I use TextMessage o
- Symfony2: check whether session exists or not
- Custom serialization for fields in Rails
- Do I need to expose a constructor in a WCF DataCon
Just extending the answer of kolossus. Most of Servlet Containers like Tomcat may use an strategy of storing the Session data to physical memory, in case if restart or web app reload.
Well the usual way to store/persist Java instances/Objects is using ObjectoutputStream, which indeed requires the Object/instance to be persisted, to implement the Serializable interface.
You can see that its mentioned in Tomcat docs that:
Link for doc.
@SessionScoped
beans are ultimately stored in the user's HTTP session.This means that when a Java EE deployment implements a session preservation scheme (for example, tomcat will attempt to save current sessions to a .ser file on server shutdown, if the deployer so chooses), those session-scoped beans would also be part of the payload that will be persisted.
A session scoped bean that isn't serializable becomes a problem here as it renders the entire HTTP session that it is a part of, un-persistable (any attempt to serialize an object that contains an unserializable member will cause a
NotSerializableException
, except with some special handling)Incidentally, that means that even if your session-scoped bean implements Serializable, all its member variables must either be serializable or be marked
transient
.In short, the entire object graph of a given HTTP session that is liable to be persisted via serialization, must either be marked as serializable or
transient
Read more:
Why does Java have transient fields?
JavaBean recommendations on serialization