Storing POJO's in Session?

9 views
Skip to first unread message

niko...@brightminds.org

unread,
Jun 19, 2021, 11:37:11 PM6/19/21
to jooby-project
Hi Everyone,

Using Jooby 2.9.6 and everything is great.  Just started using a CaffeineSessionStore wanting to throw logged in user information (POJO's) onto a session and surprised to read:

"Sessions have a lot of uses cases but the most commons are: authentication, storing information about current user, etc.

A session attribute must be a String or a primitive. The session doesn’t allow storing of arbitrary objects. It’s intended as a simple mechanism to store basic data (not an object graph)."

Why is this limitation in place?  I really need to store some simple POJO objects (not a full graph) otherwise I need to break them down into Strings and build them up i.e. convert to/from JSON or something.

Since its inception Java has allowed HttpSession.setAttribute(name, value).  I get that some have abused this mechanism with complex graphs and can run out of memory if they don't release references, etc... but on the other hand this complicates dealing with simple POJO's... e.g. load a User object from DB to display name, get their role, etc....

What am I missing here and what's the best advice if I need to store some simple objects that are not Strings or Primitives?

Thank You,

--Nikolaos


niko...@brightminds.org

unread,
Jul 17, 2021, 1:14:16 AM7/17/21
to jooby-project
Does anyone have any suggestions?

--Nikolaos

Reply all
Reply to author
Forward
0 new messages