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

> Thanks Russell,
> ok,
> I useDefaultRiakClient ( userName = "user1", userInfo = 
> "{"email":"[email protected]","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 protected]\",\"pass\":\"123123\"}","vclockAsString":null,"meta":{}}
> 
> how to make value just as {"email":"[email protected]","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.

TL;DR 
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?

Cheers

Russell

> 
> 
> _______________________________________________
> riak-users mailing list
> [email protected]
> http://lists.basho.com/mailman/listinfo/riak-users_lists.basho.com


_______________________________________________
riak-users mailing list
[email protected]
http://lists.basho.com/mailman/listinfo/riak-users_lists.basho.com

Reply via email to