2010-11-23 1 views
2

こんにちは私はデータを格納するためにVoldemortを使用しています。私のキーは単語であり、値は単語とURLの出現回数です。例:voldemortでスティングアレイを渡す方法

key :question 
value: 10, www.stackoverflow.com 

私はstring[]を使用して値を渡しています。しかし、私はclient.put ("xxxx", valuePair);を使用しようとしていましたが、私はを取得しています。java.lang.ClassCastException:[Ljava.lang.String; java.lang.Stringにキャストすることはできません。 私のコードは、この問題を解決するために私を助けてください、この

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; 
    String value = new Integer(val).toString(); 
    valuePair[0]=value; 
    valuePair[1] = "www.cnn.com"; 
    System.out.println("Executed one"); 
    StoreClientFactory factory = new SocketStoreClientFactory (cc); 
    StoreClient <String, String[]> client = factory.getStoreClient ("test"); 
    System.out.println("Executed two"); 

    client.put ("xxxx", valuePair); 
    System.out.println("Executed three"); 
    String[] ans = client.getValue("key"); 
    System.out.println("Executed four"); 
    System.out.println ("value " +ans[0] +ans[1]); 
    System.out.println("Executed 5"); 
    } 
} 

のように見えます。前もって感謝します。

答えて

0

値シリアライザの設定を変更するには、store.xmlを編集する必要があります。それは今、この権利のようになります。これは、Java配列に、それにマップしないであろうと

<value-serializer> 
     <type>json</type> 
     <schema-info>["string"]</schema-info> 
</value-serializer> 

注:

<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>string</type> 
    </value-serializer> 
    </store> 
</stores> 

を、あなたがするために必要なものvalue-serializerへの変更ですJavaのリストそれがあなたなら何であるか本当にこれはわたしが知っているほど近くにありません。

しかし、あなたはかもしれないはこのような何かしたい:次に

<value-serializer> 
     <type>json</type> 
     <schema-info>{"occurences":"int32", "site":"string"}</schema-info> 
</value-serializer> 

を、あなたは(スニペット)できます。これは便利

Map<String, Object> pair = new HashMap<String,Object>(); 
pair.put("occurences", 10); 
pair.put("site", "www.stackoverflow.com"); 

client.put("question",pair); 

System.out.println(client.get("question")); 

希望でした!

http://project-voldemort.com/design.php

JSONシリアライズタイプ詳細

: あなたは、このいくつかのドキュメントを参照してくださいすることができます
関連する問題