Indeed Express does serialize the session object behind the scenes, to support external data stores like Redis, etc.
The solution is to not put functions there. Define them somewhere else, pass them the needed arguments (even the entire session object if you want). Only put serializable data into the session object (Strings, Numbers, Objects, Arrays, and null are about it). On Wed, Jul 4, 2012 at 3:05 PM, mscdex <[email protected]> wrote: > On Jul 4, 5:35 pm, "ec.developer" <[email protected]> wrote: > > Hi all, > > I'm trying to store a class object in a session (I actually use > ExpressJS). > > For class properties everything is fine, but class methods are missed, > when > > I access the object. > > My guess (without researching) is that the object is being serialized > JSON, which does not allow for functions. > > If my guess is correct, you'd have to convert functions to strings > during the serialization process (JSON.stringify accepts a callback as > a second argument where you can do this easily) and know to > deserialize those particular property values as functions instead of > ordinary strings. > > -- > Job Board: http://jobs.nodejs.org/ > Posting guidelines: > https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines > You received this message because you are subscribed to the Google > Groups "nodejs" group. > To post to this group, send email to [email protected] > To unsubscribe from this group, send email to > [email protected] > For more options, visit this group at > http://groups.google.com/group/nodejs?hl=en?hl=en > -- Job Board: http://jobs.nodejs.org/ Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines You received this message because you are subscribed to the Google Groups "nodejs" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/nodejs?hl=en?hl=en
