Hallo Ich verwende Voldemort, um meine Daten zu speichern. Mein Schlüssel ist ein Wort und Werte sind die Anzahl der Vorkommen des Wortes und der URL. Zum Beispiel:Wie serialisieren JSON-Objekt in Java
Ich verwende Json-Objekt, um meine Werte zu setzen. Mein Code sieht wie folgt aus
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);
}
}
Und mein store.xml sieht wie folgt aus
<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>
Während ich den Code auszuführen versuchte ich folgende Ausnahme bin immer: **
Ausnahme im Thread "Haupt" voldemort.serialization.SerializationException: java.io.NotSerializableExc eption: org.json.JSONObject bei voldemort.serialization.ObjectSerializer.toBytes (ObjectSerializer.java:47) bei voldemort.store.serialized.SerializingStore.put (SerializingStore.java:109) bei voldemort.store .DelegatingStore.put (DelegatingStore.java:68) bei voldemort.client.DefaultStoreClient.put (DefaultStoreClient.java:208) bei voldemort.client.DefaultStoreClient.put (DefaultStoreClient.java:193) bei ClientExample. main (ClientExample.java:27) Verursacht von: java.io.NotSerializableException: org.json.JS ONObject bei java.io.ObjectOutputStream.writeObject0 (Unbekannt Quelle) bei java.io.ObjectOutputStream.writeObject (Unbekannt Quelle) bei voldemort.serialization.ObjectSerializer.toBytes (ObjectSerializer.java:44)
**
Können Sie mir bitte sagen, wie JSON-Objekt zu serialisieren. Vielen Dank im Voraus.