static public String userToCookieString ( boolean loggedIn , User user ) throws Exception { JSONObject cookieObj = new JSONObject ( ) ; cookieObj . put ( "logged" , loggedIn ) ; JSONObject userObj = user . toJSON ( ) ; cookieObj . put ( "user" , userObj ) ; StringWriter sw = new StringWriter ( ) ; cookieObj . write ( sw ) ; String cookieRaw = sw . toString ( ) ; String cookieStr = URLEncoder . encode ( cookieRaw , "UTF-8" ) ; cookieStr = cookieStr . replace ( "+" , "%20" ) ; return cookieStr ; }
Converts an instance of User to JSON object fit for a cookie