Precommit Hook Difficulties

Greg Pascale greg at clipboard.com
Mon Sep 19 14:42:24 EDT 2011


Scratch that - the issue doesn't actually manifest without the
decode/encode.

On Mon, Sep 19, 2011 at 10:47 AM, Greg Pascale <greg at clipboard.com> wrote:

> Actually it looks like I can remove the JSON decode/encode and I still see
> the same issue. Just reading and writing the value is enough, so all I'm
> doing now is
>
> *precommit(RiakObject) ->*
> *        Value = riak_object:get_value(RiakObject),*
> *        riak_object:apply_updates(*
> *          riak_object:update_value(RiakObject, Value)).*
>
> I'm really baffled here. The only documentation I know of for this code is
> at
> http://basho.github.com/riak-erlang-client/riak-erlang-client/riakc_obj.html and
> it really doesn't say much.
>
> -Greg
> Clipboard
>
> On Sat, Sep 17, 2011 at 4:11 PM, Greg Pascale <greg at clipboard.com> wrote:
>
>> Hi,
>>
>> I'm trying to write a simple precommit hook to modify a JSON object by
>> removing certain fields. The simplest way to do this, I figure, is to decode
>> the object's value with mochijson2, remove the fields I don't want,
>> re-encode it, and update the value.
>>
>> What happens, though, is my object ends up somehow mangled. When I inspect
>> it via curl, it sort of looks like JSON, but characters like "{" and ":"
>> seem to be replaced with garbage.
>>
>> For example, what should read "hostname":"www.google.com" looks like *
>> hostnamea"ja:la"mwww.google.coma"j*
>>
>> To try to diagnose the issue, I reduced my hook to the simplest possible
>> case. I don't even modify the JSON, I just decode the object and re-encode
>> exactly the same value, but I still have the problem. The code is pasted
>> below
>>
>> *precommit(RiakObject) ->*
>> *        Value = riak_object:get_value(RiakObject),*
>> *        {struct, TermList} = mochijson2:decode(Value),*
>> *        riak_object:apply_updates(*
>> *          riak_object:update_value(RiakObject, *
>> *                                   mochijson2:encode({struct,
>> TermList}))).*
>>
>> Can anybody point out what I'm doing wrong?
>>
>> --
>> Greg
>> Clipboard <http://www.clipboard.com> is hiring<http://www.clipboard.com/jobs>
>> !
>>
>>
>
>
> --
> Greg
> Clipboard <http://www.clipboard.com> is hiring<http://www.clipboard.com/jobs>
> !
>
>


-- 
Greg
Clipboard <http://www.clipboard.com> is hiring<http://www.clipboard.com/jobs>
!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.basho.com/pipermail/riak-users_lists.basho.com/attachments/20110919/c19f8b6c/attachment.html>


More information about the riak-users mailing list