--- parser3/src/classes/json.C 2014/05/04 01:38:01 1.30 +++ parser3/src/classes/json.C 2015/03/17 07:28:43 1.34 @@ -18,7 +18,7 @@ #include "pa_vxdoc.h" #endif -volatile const char * IDENT_JSON_C="$Id: json.C,v 1.30 2014/05/04 01:38:01 misha Exp $"; +volatile const char * IDENT_JSON_C="$Id: json.C,v 1.34 2015/03/17 07:28:43 misha Exp $"; // class @@ -369,7 +369,7 @@ const String& value_json_string(String:: Value* method=options.methods->get(v.type()); if(!method){ method=options.methods->first_that(based_on, &v); - options.methods->put(key, method ? method : VVoid::get()); + options.methods->put(v.type(), method ? method : VVoid::get()); } if(method && !method->is_void()) { Junction* junction=method->get_junction(); @@ -427,6 +427,11 @@ static void _string(Request& r, MethodPa if(!json.set_file_format(svalue)) throw Exception(PARSER_RUNTIME, &svalue, "must be 'base64', 'text' or 'stat'"); valid_options++; + } else if(key == "void" && value->is_string()){ + const String& svalue=value->as_string(); + if(!json.set_void_format(svalue)) + throw Exception(PARSER_RUNTIME, &svalue, "must be 'string' or 'null'"); + valid_options++; #ifdef XML } else if(key == "xdoc" && (vvalue = value->get_hash())){ json.xdoc_options=new XDocOutputOptions(); @@ -447,9 +452,11 @@ static void _string(Request& r, MethodPa // special handling for $._default if(VHash* vhash=static_cast(params[1].as(VHASH_TYPE))) if(Value* value=vhash->get_default()) { + if(!value->is_string()){ Junction* junction=value->get_junction(); if(!junction || !junction->method || !junction->method->params_names || junction->method->params_names->count() != 3) - throw Exception(PARSER_RUNTIME, 0, "$.%s must be parser method with 3 parameters", HASH_DEFAULT_ELEMENT_NAME); + throw Exception(PARSER_RUNTIME, 0, "$.%s must be string or parser method with 3 parameters", HASH_DEFAULT_ELEMENT_NAME); + } json.default_method=value; } @@ -457,7 +464,7 @@ static void _string(Request& r, MethodPa json.methods=methods; } - const String& result_string=value_json_string(String::Body(), params[0], json); + const String& result_string=value_json_string(String::Body(), r.process_to_value(params[0]), json); String::Body result_body=result_string.cstr_to_string_body_untaint(String::L_JSON, r.connection(false), &r.charsets); r.write_pass_lang(*new String(result_body, String::L_AS_IS)); }