riak java client

Russell Brown russell.brown at me.com
Wed Nov 16 12:16:18 EST 2011

On 16 Nov 2011, at 16:13, sergey wrote:

> Thanks Russell,
> ok,
> I useDefaultRiakClient ( userName = "user1", userInfo = "{"email":"email at email.com","pass":"123123"}" ):
> riakObject = RiakObjectBuilder.newBuilder("users", userName).withContentType("application/json").withValue(userInfo).build
> and store:
> client.fetchBucket("users").execute.store(riakObject).execute
> in result I have in store:
> Content Type application/json;charset=UTF-8
> but value as: {"value":"eyJlbWFpbCI6ImVtYWlsQGVtYWlsLmNvbSIsInBhc3MiOiIxMjMxMjMifQ==","lastModified":null,"contentType":"application/json;charset=utf-8","bucket":"users","vtag":null,"links":[],"vclock":null,"valueAsString":"{\"email\":\"email at email.com\",\"pass\":\"123123\"}","vclockAsString":null,"meta":{}}
> how to make value just as {"email":"email at email.com","pass":"123123"}?

OK, long explanation below. You've uncovered a wart.

By default every store and fetch operation requires a Converter<T> to be present. And, to make life easy, by default, I provide the JSONConverter<T>, that converts the object it is given to JSON. This is a problem if you use the raw IRiakObject type since the whole thing gets serialised, rather than just the values. The fix, which I have, is to check the type, and if it is IRiakObject then don't use the converter. The longer term fix is to have a registry of converters mapped to types, but that is not done yet.

The problem really is that the higher level API expects you to store domain things, not lower level, Riak things.

I know this seems bad, but I wanted an API that gave a flexibility *and* pushed people towards using domain specific classes, since handling conflicts requires that. It does mean there is this slightly more verbose hoop to jump through when you want to use a plain IRiakObject from the higher level client API.

Store a domain specific java object with two fields, `email` and `pass` OR provide a PassThroughConverter to the StoreOperation OR  if you are dealing directly with IRiakObject, use RawClient. I'm working on a silent solution that detects the IRiakObject type and does not convert it.

Does it make sense?



> _______________________________________________
> riak-users mailing list
> riak-users at lists.basho.com
> http://lists.basho.com/mailman/listinfo/riak-users_lists.basho.com

More information about the riak-users mailing list