JSONObject class of package org.codehaus.groovy.grails.web.json does not implement Serializable.
I want to make this object serializable as I am using session replication among application servers and JSONObject gets saved in session.
I have two options to achieve this:
- Subclass
JSONObjects that implementsSerializable. - use
toString()method onJSONObjectobject while saving this object in session.
Can anyone please suggest which one of two options should I use and what is the reason?
I think the
toStringmethod is what’s intended to be used here. That method already returns the JSON text of the object, which is suitable for transmitting or storing.