ext/oj/mimic_json.c in oj-3.13.14 vs ext/oj/mimic_json.c in oj-3.13.15
- old
+ new
@@ -386,10 +386,14 @@
oj_dump_obj_to_json_using_params(*argv, copts, &out, argc - 1, argv + 1);
} else {
VALUE active_hack[1];
if (Qundef == state_class) {
+ rb_warn(
+ "Oj::Rails.mimic_JSON was called implicitly. "
+ "Call it explicitly beforehand if you want to remove this warning."
+ );
oj_define_mimic_json(0, NULL, Qnil);
}
active_hack[0] = rb_funcall(state_class, oj_new_id, 0);
oj_dump_obj_to_json_using_params(*argv, copts, &out, 1, active_hack);
}
@@ -479,10 +483,14 @@
}
if (!oj_hash_has_key(h, oj_array_nl_sym)) {
rb_hash_aset(h, oj_array_nl_sym, rb_str_new2("\n"));
}
if (Qundef == state_class) {
+ rb_warn(
+ "Oj::Rails.mimic_JSON was called implicitly. "
+ "Call it explicitly beforehand if you want to remove this warning."
+ );
oj_define_mimic_json(0, NULL, Qnil);
}
rargs[1] = rb_funcall(state_class, oj_new_id, 1, h);
copts.str_rx.head = NULL;
@@ -534,18 +542,10 @@
rb_check_type(v, T_CLASS);
pi->options.array_class = v;
}
} else if (oj_decimal_class_sym == k) {
pi->options.compat_bigdec = (oj_bigdecimal_class == v);
- } else if (oj_max_nesting_sym == k) {
- if (Qtrue == v) {
- pi->max_depth = 100;
- } else if (Qfalse == v || Qnil == v) {
- pi->max_depth = 0;
- } else if (T_FIXNUM == rb_type(v)) {
- pi->max_depth = NUM2INT(v);
- }
}
return ST_CONTINUE;
}
static VALUE mimic_parse_core(int argc, VALUE *argv, VALUE self, bool bang) {
@@ -571,14 +571,24 @@
pi.options.bigdec_load = RubyDec;
pi.options.mode = CompatMode;
pi.max_depth = 100;
if (Qnil != ropts) {
+ VALUE v;
+
if (T_HASH != rb_type(ropts)) {
rb_raise(rb_eArgError, "options must be a hash.");
}
rb_hash_foreach(ropts, parse_options_cb, (VALUE)&pi);
+ v = rb_hash_lookup(ropts, oj_max_nesting_sym);
+ if (Qtrue == v) {
+ pi.max_depth = 100;
+ } else if (Qfalse == v || Qnil == v) {
+ pi.max_depth = 0;
+ } else if (T_FIXNUM == rb_type(v)) {
+ pi.max_depth = NUM2INT(v);
+ }
oj_parse_opt_match_string(&pi.options.str_rx, ropts);
if (Yes == pi.options.create_ok && Yes == pi.options.sym_key) {
rb_raise(rb_eArgError, ":symbolize_names and :create_additions can not both be true.");
}
}