Marcel,
{ok,Pid} = riakc_pb_socket:start_link("127.0.0.1", 8087),
> Tuple = "{\"id\",22}",
>
That is not valid JSON, first of all.
> Obj = riakc_obj:new("mm","1",Tuple),
>
Make sure that you set the content type here, otherwise it won't be
detected on the Java side. (example below)
> riakc_pb_socket:put(Pid,Obj),
>
> After then we try to read from risk-java-client:
>
> RiakClient httpClient = new RiakClient("http://10.10.10.61:8098/riak");
> IRiakClient client = RiakFactory.httpClient(httpClient);
> Bucket b = client.fetchBucket("mm").execute();
> IRiakObject fetched = b.fetch("1").execute();
> String decodedString = new String(fetched.getValue());
> System.out.println(decodedString);
>
> I convert the Object to an HexString: 83 6B 00 05 7B 22 6E 22 7D
>
>
Decoding that byte array in Erlang gives:
1> <<16#83,16#6B,0,5,16#7B,16#22,16#6E,16#22,16#7D>>.
<<131,107,0,5,123,34,110,34,125>>
2> binary_to_term(v(1)).
"{\"n\"}"
3>
The default behavior of the Erlang client is to serialize terms to binary
unless the content type is explicit and the value of the object is a
binary. Try this instead:
Value = mochijson2:encode({struct, [{id, 22}]}),
Obj = riakc_obj:new(<<"mm">>,<<"1">>,Value,"application/json"),
riakc_pb_socket:put(Pid, Obj)
Then re-read it from the Java side and you should get what you expect.
My question is:
>
> 1. What are the first 4 bytes ?
>
A binary that starts with byte 131 is typically in Erlang
term_to_binary/binary_to_term format.
> 2. how can i receive a string with out the 4 bytes ?
>
See above.
> 3. How can i convert the string into a JSON Object ?
>
>
See above, and then use Jackson to decode the value (I believe the Java
client may do this automatically for you).
--
Sean Cribbs <[email protected]>
Software Engineer
Basho Technologies, Inc.
http://basho.com/
_______________________________________________
riak-users mailing list
[email protected]
http://lists.basho.com/mailman/listinfo/riak-users_lists.basho.com