Reputation: 245
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:
JSONObject
s that implements Serializable
. toString()
method on JSONObject
object while saving this object in session.Can anyone please suggest which one of two options should I use and what is the reason?
Upvotes: 4
Views: 9022
Reputation: 2439
You don't need to serialize JSON, it is already in a store-able form(sort of the whole point of JSON). Grails has JSON parsers and "slurpers" all ready to use for you. So just store the JSON data as a string and use a parser on it to read it back out of the file.
Upvotes: 1
Reputation: 406095
I think the toString
method 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.
Upvotes: 6