Reputation: 30172
I'm using json.org JSONObject. I've tried to serialize it to memcache and got the not so cool java.io.NotSerializableException: org.json.JSONObject
. Looking at the JSONObject code it seems that it's nothing more then a Map wrapped by JSON logic. Why not make it serializble then?
I would like to be able to store the object into memcache in an easy interface. Is there a similar API implementation of JSONObject that is also serializble. Alternatively, what memcache friendly serialization / deserialization technique do you use ?
Thank you, Maxim.
Upvotes: 1
Views: 4153
Reputation: 7778
JSONObject
s are meant be sent as simple strings. So instead of storing the Java serialized form of your JSONObject
s you should store the stringified forms.
Upvotes: 5
Reputation: 30172
I have found http://code.google.com/p/json-simple/ to be API compatible implementation of org.json.JSONObject. It does not have all the getDouble, getLong, getJSONArray methods but other then that the concepts are pretty much the same.
It excels over org.json implementation by the fact that it simply extends HashMap for JSONObject and ArrayList for JSONArray making these objects by definition serializble and thus cacheable.
Upvotes: 1
Reputation: 5327
if you use org.json.JSONObject, it doesn't implement the Serializable interface. For that reason it can't be serialized. Instead, you can put the String version of JSONObject into MemCache.
Upvotes: 3