I've recently been interested in couchdb and the java library to
access it couchdb4j which uses json-lib to create it's JSON messages,
which is how clients communicate to the server.
Couchdb uses "views" instead of queries. These views return objects
via a javascript function that the designer defines. These JavaScript
functions are encoded into JSON messages and sent to the server when
the view is defined.
couchdb4j was unable to create a view because when the javascript
function is added to a JSONObject, json-lib converts that string to a
function (no quotes). As a result couchdb's JSON decoder receives the
unquoted function where it is expecting a string and it fails.
In the process of figuring this out, I also noticed that
http://www.jsonlint.com/ doesn't consider values of non-quoted
functions valid JSON. Of course I have no idea who made that site or
what authority they have, but I suppose it's worth mentioning.
I was able to modify the behavior by changing this method so that it
always returns false. Upon doing this, couchdb4j was able to interact
with couchdb properly.
JSONUtils.java:286
public static boolean isFunction( Object obj ) {
//if( obj instanceof String ){
// String str = (String) obj;
// return str.startsWith( FUNCTION_PREFIX ) &&
FUNCTION_MACTHER.matches( str );
//}
//if( obj instanceof JSONFunction ){
// return true;
//}
return false;
}
I think it's good for couchdb4j have a non-modified versions of
json-lib as it's dependency, so I'm asking if there is a way in which
the functionality I need (JavaScript functions as quoted strings in
values) can be made available through json-lib.
Thanks,
--
Chad Skeeters
1-210-881-0453
|