key :question value: 10,www.stackoverflow.com
我正在使用Json对象来放置我的值.
我的代码看起来像这样
import org.json.JSONObject; import com.Metaparadigm.jsonrpc.JSONSerializer; import voldemort.client.ClientConfig; import voldemort.client.SocketStoreClientFactory; import voldemort.client.StoreClient; import voldemort.client.StoreClientFactory; public class ClientExample { public static void main (String [] args) { String bootstrapUrl = "tcp://localhost:6666"; ClientConfig cc = new ClientConfig (); cc.setBootstrapUrls (bootstrapUrl); String[] valuePair = new String[2]; int val = 1; StoreClientFactory factory = new SocketStoreClientFactory (cc); StoreClient client = factory.getStoreClient("test"); JSONObject json = new JSONObject(); json.put("occurence",val); json.put("url","www.cnn.com"); client.put("foo",json); } }
我的store.xml看起来像这样
<stores> <store> <name>test</name> <persistence>bdb</persistence> <routing>client</routing> <replication-factor>1</replication-factor> <required-reads>1</required-reads> <required-writes>1</required-writes> <key-serializer> <type>string</type> </key-serializer> <value-serializer> <type>java-serialization</type> <schema-info>"Compount Types"</schema-info> </value-serializer> </store> </stores>
当我试图运行代码时,我得到以下异常:
**
Exception in thread “main”
voldemort.serialization.SerializationException:
java.io.NotSerializableException:
org.json.JSONObject at
voldemort.serialization.ObjectSerializer.toBytes(ObjectSerializer.java:47)
at
voldemort.store.serialized.SerializingStore.put(SerializingStore.java:109)
at
voldemort.store.DelegatingStore.put(DelegatingStore.java:68)
at
voldemort.client.DefaultStoreClient.put(DefaultStoreClient.java:208)
at
voldemort.client.DefaultStoreClient.put(DefaultStoreClient.java:193)
at
ClientExample.main(ClientExample.java:27)
Caused by:
java.io.NotSerializableException:
org.json.JSONObject at
java.io.ObjectOutputStream.writeObject0(Unknown
Source) at
java.io.ObjectOutputStream.writeObject(Unknown
Source) at
voldemort.serialization.ObjectSerializer.toBytes(ObjectSerializer.java:44)
**
你能否告诉我如何序列化JSON对象.提前谢谢.