I have a project for school and I have to use Java. Recently I found play framework and I want to try to use it. It\'s easy enough for a quick start, but I ran into a problem wi
Another option is to convert your objects into JSON. I created a simple Util for this and used FlexJSON to serialise my objects into JSON.
import play.Logger;
import play.mvc.Http;
import play.mvc.Http.Session;
import flexjson.JSONDeserializer;
import flexjson.JSONSerializer;
public class SessionManager {
private static JSONSerializer s = new JSONSerializer();
public static void addSession(String key, Object value) {
if(value != null) {
Session session = Http.Context.current().session();
session.put(key, s.deepSerialize(value));
} else {
Logger.info("Value for " + key + " is null");
}
}
public static T get(String key) {
Session session = Http.Context.current().session();
final String value = session.get(key);
if (value == null) {
return null;
}
return new JSONDeserializer().deserialize(value);
}
}
NOTE: You'll have to manage cleaning after your work and keep in mind that since this is stored in the cookie, it is not as secure.