oj 3.10.0 → 3.10.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ext/oj/compat.c +5 -5
- data/ext/oj/custom.c +4 -2
- data/ext/oj/dump_compat.c +2 -1
- data/ext/oj/dump_object.c +4 -2
- data/ext/oj/dump_strict.c +6 -5
- data/ext/oj/extconf.rb +5 -0
- data/ext/oj/mimic_json.c +11 -1
- data/ext/oj/oj.c +3 -1
- data/ext/oj/parse.c +1 -1
- data/ext/oj/rails.c +34 -5
- data/ext/oj/sparse.c +1 -0
- data/ext/oj/wab.c +9 -9
- data/lib/oj/version.rb +1 -1
- data/test/foo.rb +42 -157
- data/test/test_custom.rb +19 -4
- data/test/test_rails.rb +26 -0
- data/test/tests.rb +1 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3dd1cae4ccf720f35b777913213b66466c7d9752055c60d828cdf681956731a3
|
4
|
+
data.tar.gz: e913c57a4619bfbea97144f6f4783219aca294e598c8c6449ddfc6cb997b46f7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dc0b7bd0e9ea90e69eda6a6205c09540e2217f9ccdcb3c6e937fb82e4b979fada30a028b64559ac5dfddc22afb9d4302669de35315bb5c5392ad100a373bb472
|
7
|
+
data.tar.gz: 8d8ad9eeb68fb2d058c3f499ad51fc8c50d3349b36a237769f996a43de58449fbae36d3bff82c6be6a16828331f12aa19df6a1ef90b5bdff78ecdf732450a268
|
data/ext/oj/compat.c
CHANGED
@@ -65,7 +65,7 @@ hash_set_cstr(ParseInfo pi, Val kval, const char *str, size_t len, const char *o
|
|
65
65
|
static VALUE
|
66
66
|
start_hash(ParseInfo pi) {
|
67
67
|
volatile VALUE h;
|
68
|
-
|
68
|
+
|
69
69
|
if (Qnil != pi->options.hash_class) {
|
70
70
|
h = rb_class_new_instance(0, NULL, pi->options.hash_class);
|
71
71
|
} else {
|
@@ -87,7 +87,7 @@ end_hash(struct _parseInfo *pi) {
|
|
87
87
|
clas = oj_name2class(pi, parent->classname, parent->clen, 0, rb_eArgError);
|
88
88
|
if (Qundef != clas) { // else an error
|
89
89
|
ID creatable = rb_intern("json_creatable?");
|
90
|
-
|
90
|
+
|
91
91
|
if (!rb_respond_to(clas, creatable) || Qtrue == rb_funcall(clas, creatable, 0)) {
|
92
92
|
parent->val = rb_funcall(clas, oj_json_create_id, 1, parent->val);
|
93
93
|
}
|
@@ -146,7 +146,7 @@ add_num(ParseInfo pi, NumInfo ni) {
|
|
146
146
|
static void
|
147
147
|
hash_set_num(struct _parseInfo *pi, Val parent, NumInfo ni) {
|
148
148
|
volatile VALUE rval = oj_num_as_value(ni);
|
149
|
-
|
149
|
+
|
150
150
|
if (!oj_use_hash_alt && rb_cHash != rb_obj_class(parent->val)) {
|
151
151
|
// The rb_hash_set would still work but the unit tests for the
|
152
152
|
// json gem require the less efficient []= method be called to set
|
@@ -192,7 +192,7 @@ static void
|
|
192
192
|
array_append_num(ParseInfo pi, NumInfo ni) {
|
193
193
|
Val parent = stack_peek(&pi->stack);
|
194
194
|
volatile VALUE rval = oj_num_as_value(ni);
|
195
|
-
|
195
|
+
|
196
196
|
if (!oj_use_array_alt && rb_cArray != rb_obj_class(parent->val)) {
|
197
197
|
// The rb_ary_push would still work but the unit tests for the json
|
198
198
|
// gem require the less efficient << method be called to push the
|
@@ -274,7 +274,7 @@ oj_compat_load(int argc, VALUE *argv, VALUE self) {
|
|
274
274
|
pi.options.nilnil = Yes;
|
275
275
|
pi.options.empty_string = Yes;
|
276
276
|
oj_set_compat_callbacks(&pi);
|
277
|
-
|
277
|
+
|
278
278
|
if (T_STRING == rb_type(*argv)) {
|
279
279
|
return oj_pi_parse(argc, argv, &pi, 0, 0, false);
|
280
280
|
} else {
|
data/ext/oj/custom.c
CHANGED
@@ -297,7 +297,8 @@ static struct _code codes[] = {
|
|
297
297
|
};
|
298
298
|
|
299
299
|
static int
|
300
|
-
hash_cb(VALUE key, VALUE value,
|
300
|
+
hash_cb(VALUE key, VALUE value, VALUE ov) {
|
301
|
+
Out out = (Out)ov;
|
301
302
|
int depth = out->depth;
|
302
303
|
|
303
304
|
if (oj_dump_ignore(out->opts, value)) {
|
@@ -592,7 +593,8 @@ dump_common(VALUE obj, int depth, Out out) {
|
|
592
593
|
}
|
593
594
|
|
594
595
|
static int
|
595
|
-
dump_attr_cb(ID key, VALUE value,
|
596
|
+
dump_attr_cb(ID key, VALUE value, VALUE ov) {
|
597
|
+
Out out = (Out)ov;
|
596
598
|
int depth = out->depth;
|
597
599
|
size_t size;
|
598
600
|
const char *attr;
|
data/ext/oj/dump_compat.c
CHANGED
@@ -648,7 +648,8 @@ dump_float(VALUE obj, int depth, Out out, bool as_ok) {
|
|
648
648
|
}
|
649
649
|
|
650
650
|
static int
|
651
|
-
hash_cb(VALUE key, VALUE value,
|
651
|
+
hash_cb(VALUE key, VALUE value, VALUE ov) {
|
652
|
+
Out out = (Out)ov;
|
652
653
|
int depth = out->depth;
|
653
654
|
|
654
655
|
if (out->omit_nil && Qnil == value) {
|
data/ext/oj/dump_object.c
CHANGED
@@ -224,7 +224,8 @@ dump_sym(VALUE obj, int depth, Out out, bool as_ok) {
|
|
224
224
|
}
|
225
225
|
|
226
226
|
static int
|
227
|
-
hash_cb(VALUE key, VALUE value,
|
227
|
+
hash_cb(VALUE key, VALUE value, VALUE ov) {
|
228
|
+
Out out = (Out)ov;
|
228
229
|
int depth = out->depth;
|
229
230
|
long size = depth * out->indent + 1;
|
230
231
|
|
@@ -348,7 +349,8 @@ dump_hash_class(VALUE obj, VALUE clas, int depth, Out out) {
|
|
348
349
|
|
349
350
|
#ifdef HAVE_RB_IVAR_FOREACH
|
350
351
|
static int
|
351
|
-
dump_attr_cb(ID key, VALUE value,
|
352
|
+
dump_attr_cb(ID key, VALUE value, VALUE ov) {
|
353
|
+
Out out = (Out)ov;
|
352
354
|
int depth = out->depth;
|
353
355
|
size_t size = depth * out->indent + 1;
|
354
356
|
const char *attr = rb_id2name(key);
|
data/ext/oj/dump_strict.c
CHANGED
@@ -45,7 +45,7 @@ dump_float(VALUE obj, int depth, Out out, bool as_ok) {
|
|
45
45
|
cnt = 3;
|
46
46
|
} else {
|
47
47
|
NanDump nd = out->opts->dump_opts.nan_dump;
|
48
|
-
|
48
|
+
|
49
49
|
if (AutoNan == nd) {
|
50
50
|
nd = RaiseNan;
|
51
51
|
}
|
@@ -195,11 +195,12 @@ dump_array(VALUE a, int depth, Out out, bool as_ok) {
|
|
195
195
|
}
|
196
196
|
|
197
197
|
static int
|
198
|
-
hash_cb(VALUE key, VALUE value,
|
198
|
+
hash_cb(VALUE key, VALUE value, VALUE ov) {
|
199
|
+
Out out = (Out)ov;
|
199
200
|
int depth = out->depth;
|
200
201
|
long size;
|
201
202
|
int rtype = rb_type(key);
|
202
|
-
|
203
|
+
|
203
204
|
if (rtype != T_STRING && rtype != T_SYMBOL) {
|
204
205
|
rb_raise(rb_eTypeError, "In :strict and :null mode all Hash keys must be Strings or Symbols, not %s.\n", rb_class2name(rb_obj_class(key)));
|
205
206
|
}
|
@@ -359,7 +360,7 @@ static DumpFunc strict_funcs[] = {
|
|
359
360
|
void
|
360
361
|
oj_dump_strict_val(VALUE obj, int depth, Out out) {
|
361
362
|
int type = rb_type(obj);
|
362
|
-
|
363
|
+
|
363
364
|
if (Yes == out->opts->trace) {
|
364
365
|
oj_trace("dump", obj, __FILE__, __LINE__, depth, TraceIn);
|
365
366
|
}
|
@@ -408,7 +409,7 @@ static DumpFunc null_funcs[] = {
|
|
408
409
|
void
|
409
410
|
oj_dump_null_val(VALUE obj, int depth, Out out) {
|
410
411
|
int type = rb_type(obj);
|
411
|
-
|
412
|
+
|
412
413
|
if (Yes == out->opts->trace) {
|
413
414
|
oj_trace("dump", obj, __FILE__, __LINE__, depth, TraceOut);
|
414
415
|
}
|
data/ext/oj/extconf.rb
CHANGED
@@ -42,6 +42,11 @@ end
|
|
42
42
|
|
43
43
|
$CPPFLAGS += ' -Wall'
|
44
44
|
#puts "*** $CPPFLAGS: #{$CPPFLAGS}"
|
45
|
+
# Adding the __attribute__ flag only works with gcc compilers and even then it
|
46
|
+
# does not work to check args with varargs so just remove the check.
|
47
|
+
CONFIG['warnflags'].slice!(/ -Wsuggest-attribute=format/)
|
48
|
+
CONFIG['warnflags'].slice!(/ -Wdeclaration-after-statement/)
|
49
|
+
CONFIG['warnflags'].slice!(/ -Wmissing-noreturn/)
|
45
50
|
|
46
51
|
create_makefile(File.join(extension_name, extension_name))
|
47
52
|
|
data/ext/oj/mimic_json.c
CHANGED
@@ -199,6 +199,7 @@ mimic_dump(int argc, VALUE *argv, VALUE self) {
|
|
199
199
|
struct _out out;
|
200
200
|
struct _options copts = oj_default_options;
|
201
201
|
VALUE rstr;
|
202
|
+
VALUE active_hack[1];
|
202
203
|
|
203
204
|
copts.str_rx.head = NULL;
|
204
205
|
copts.str_rx.tail = NULL;
|
@@ -216,6 +217,7 @@ mimic_dump(int argc, VALUE *argv, VALUE self) {
|
|
216
217
|
*/
|
217
218
|
copts.dump_opts.max_depth = MAX_DEPTH; // when using dump there is no limit
|
218
219
|
out.omit_nil = copts.dump_opts.omit_nil;
|
220
|
+
|
219
221
|
if (2 <= argc) {
|
220
222
|
int limit;
|
221
223
|
|
@@ -230,7 +232,15 @@ mimic_dump(int argc, VALUE *argv, VALUE self) {
|
|
230
232
|
copts.dump_opts.max_depth = limit;
|
231
233
|
}
|
232
234
|
}
|
233
|
-
|
235
|
+
// ActiveSupport in active_support/core_ext/object/json.rb check the
|
236
|
+
// optional argument type to to_json and it the argument is a
|
237
|
+
// ::JSON::State it calls the JSON gem code otherwise it calls the active
|
238
|
+
// support encoder code. To make sure the desired branch is called a
|
239
|
+
// default ::JSON::State argument is passed in. Basically a hack to get
|
240
|
+
// around the active support hack so two wrongs make a right this time.
|
241
|
+
active_hack[0] = rb_funcall(state_class, oj_new_id, 0);
|
242
|
+
oj_dump_obj_to_json_using_params(*argv, &copts, &out, 1, active_hack);
|
243
|
+
|
234
244
|
if (0 == out.buf) {
|
235
245
|
rb_raise(rb_eNoMemError, "Not enough memory.");
|
236
246
|
}
|
data/ext/oj/oj.c
CHANGED
@@ -766,7 +766,9 @@ oj_parse_options(VALUE ropts, Options copts) {
|
|
766
766
|
}
|
767
767
|
|
768
768
|
static int
|
769
|
-
match_string_cb(VALUE key, VALUE value,
|
769
|
+
match_string_cb(VALUE key, VALUE value, VALUE rx) {
|
770
|
+
RxClass rc = (RxClass)rx;
|
771
|
+
|
770
772
|
if (T_CLASS != rb_type(value)) {
|
771
773
|
rb_raise(rb_eArgError, "for :match_string, the hash values must be a Class.");
|
772
774
|
}
|
data/ext/oj/parse.c
CHANGED
data/ext/oj/rails.c
CHANGED
@@ -87,7 +87,8 @@ copy_opts(ROptTable src, ROptTable dest) {
|
|
87
87
|
}
|
88
88
|
|
89
89
|
static int
|
90
|
-
dump_attr_cb(ID key, VALUE value,
|
90
|
+
dump_attr_cb(ID key, VALUE value, VALUE ov) {
|
91
|
+
Out out = (Out)ov;
|
91
92
|
int depth = out->depth;
|
92
93
|
size_t size = depth * out->indent + 1;
|
93
94
|
const char *attr = rb_id2name(key);
|
@@ -1011,9 +1012,11 @@ rails_encode(int argc, VALUE *argv, VALUE self) {
|
|
1011
1012
|
}
|
1012
1013
|
}
|
1013
1014
|
|
1015
|
+
// TBD provide a get function as well
|
1014
1016
|
static VALUE
|
1015
1017
|
rails_use_standard_json_time_format(VALUE self, VALUE state) {
|
1016
1018
|
if (Qtrue == state || Qfalse == state) {
|
1019
|
+
// no change needed
|
1017
1020
|
} else if (Qnil == state) {
|
1018
1021
|
state = Qfalse;
|
1019
1022
|
} else {
|
@@ -1025,6 +1028,11 @@ rails_use_standard_json_time_format(VALUE self, VALUE state) {
|
|
1025
1028
|
return state;
|
1026
1029
|
}
|
1027
1030
|
|
1031
|
+
static VALUE
|
1032
|
+
rails_use_standard_json_time_format_get(VALUE self) {
|
1033
|
+
return xml_time ? Qtrue : Qfalse;
|
1034
|
+
}
|
1035
|
+
|
1028
1036
|
static VALUE
|
1029
1037
|
rails_escape_html_entities_in_json(VALUE self, VALUE state) {
|
1030
1038
|
rb_iv_set(self, "@escape_html_entities_in_json", state);
|
@@ -1033,6 +1041,11 @@ rails_escape_html_entities_in_json(VALUE self, VALUE state) {
|
|
1033
1041
|
return state;
|
1034
1042
|
}
|
1035
1043
|
|
1044
|
+
static VALUE
|
1045
|
+
rails_escape_html_entities_in_json_get(VALUE self) {
|
1046
|
+
return escape_html ? Qtrue : Qfalse;
|
1047
|
+
}
|
1048
|
+
|
1036
1049
|
static VALUE
|
1037
1050
|
rails_time_precision(VALUE self, VALUE prec) {
|
1038
1051
|
rb_iv_set(self, "@time_precision", prec);
|
@@ -1056,7 +1069,12 @@ rails_set_encoder(VALUE self) {
|
|
1056
1069
|
VALUE encoding;
|
1057
1070
|
VALUE pv;
|
1058
1071
|
VALUE verbose;
|
1072
|
+
VALUE enc = resolve_classpath("ActiveSupport::JSON::Encoding");
|
1059
1073
|
|
1074
|
+
if (Qnil != enc) {
|
1075
|
+
escape_html = Qtrue == rb_iv_get(self, "@escape_html_entities_in_json");
|
1076
|
+
xml_time = Qtrue == rb_iv_get(enc, "@use_standard_json_time_format");
|
1077
|
+
}
|
1060
1078
|
if (rb_const_defined_at(rb_cObject, rb_intern("ActiveSupport"))) {
|
1061
1079
|
active = rb_const_get_at(rb_cObject, rb_intern("ActiveSupport"));
|
1062
1080
|
} else {
|
@@ -1073,11 +1091,15 @@ rails_set_encoder(VALUE self) {
|
|
1073
1091
|
rb_gv_set("$VERBOSE", Qfalse);
|
1074
1092
|
rb_undef_method(encoding, "use_standard_json_time_format=");
|
1075
1093
|
rb_define_module_function(encoding, "use_standard_json_time_format=", rails_use_standard_json_time_format, 1);
|
1094
|
+
rb_undef_method(encoding, "use_standard_json_time_format");
|
1095
|
+
rb_define_module_function(encoding, "use_standard_json_time_format", rails_use_standard_json_time_format_get, 0);
|
1076
1096
|
|
1077
1097
|
pv = rb_iv_get(encoding, "@escape_html_entities_in_json");
|
1078
1098
|
escape_html = Qtrue == pv;
|
1079
1099
|
rb_undef_method(encoding, "escape_html_entities_in_json=");
|
1080
1100
|
rb_define_module_function(encoding, "escape_html_entities_in_json=", rails_escape_html_entities_in_json, 1);
|
1101
|
+
rb_undef_method(encoding, "escape_html_entities_in_json");
|
1102
|
+
rb_define_module_function(encoding, "escape_html_entities_in_json", rails_escape_html_entities_in_json_get, 0);
|
1081
1103
|
|
1082
1104
|
pv = rb_iv_get(encoding, "@time_precision");
|
1083
1105
|
oj_default_options.sec_prec = NUM2INT(pv);
|
@@ -1289,7 +1311,8 @@ dump_array(VALUE a, int depth, Out out, bool as_ok) {
|
|
1289
1311
|
}
|
1290
1312
|
|
1291
1313
|
static int
|
1292
|
-
hash_cb(VALUE key, VALUE value,
|
1314
|
+
hash_cb(VALUE key, VALUE value, VALUE ov) {
|
1315
|
+
Out out = (Out)ov;
|
1293
1316
|
int depth = out->depth;
|
1294
1317
|
long size;
|
1295
1318
|
int rtype = rb_type(key);
|
@@ -1402,14 +1425,17 @@ dump_hash(VALUE obj, int depth, Out out, bool as_ok) {
|
|
1402
1425
|
|
1403
1426
|
static void
|
1404
1427
|
dump_obj(VALUE obj, int depth, Out out, bool as_ok) {
|
1428
|
+
VALUE clas;
|
1429
|
+
|
1405
1430
|
if (oj_code_dump(oj_compat_codes, obj, depth, out)) {
|
1406
1431
|
out->argc = 0;
|
1407
1432
|
return;
|
1408
1433
|
}
|
1434
|
+
clas = rb_obj_class(obj);
|
1409
1435
|
if (as_ok) {
|
1410
1436
|
ROpt ro;
|
1411
1437
|
|
1412
|
-
if (NULL != (ro = oj_rails_get_opt(out->ropts,
|
1438
|
+
if (NULL != (ro = oj_rails_get_opt(out->ropts, clas)) && ro->on) {
|
1413
1439
|
ro->dump(obj, depth, out, as_ok);
|
1414
1440
|
} else if (Yes == out->opts->raw_json && rb_respond_to(obj, oj_raw_json_id)) {
|
1415
1441
|
oj_dump_raw_json(obj, depth, out);
|
@@ -1417,6 +1443,8 @@ dump_obj(VALUE obj, int depth, Out out, bool as_ok) {
|
|
1417
1443
|
dump_as_json(obj, depth, out, true);
|
1418
1444
|
} else if (rb_respond_to(obj, oj_to_hash_id)) {
|
1419
1445
|
dump_to_hash(obj, depth, out);
|
1446
|
+
} else if (oj_bigdecimal_class == clas) {
|
1447
|
+
dump_bigdecimal(obj, depth, out, false);
|
1420
1448
|
} else {
|
1421
1449
|
oj_dump_obj_to_s(obj, out);
|
1422
1450
|
}
|
@@ -1425,6 +1453,8 @@ dump_obj(VALUE obj, int depth, Out out, bool as_ok) {
|
|
1425
1453
|
} else if (rb_respond_to(obj, oj_to_hash_id)) {
|
1426
1454
|
// Always attempt to_hash.
|
1427
1455
|
dump_to_hash(obj, depth, out);
|
1456
|
+
} else if (oj_bigdecimal_class == clas) {
|
1457
|
+
dump_bigdecimal(obj, depth, out, false);
|
1428
1458
|
} else {
|
1429
1459
|
oj_dump_obj_to_s(obj, out);
|
1430
1460
|
}
|
@@ -1442,8 +1472,7 @@ static DumpFunc rails_funcs[] = {
|
|
1442
1472
|
dump_array, // RUBY_T_ARRAY = 0x07,
|
1443
1473
|
dump_hash, // RUBY_T_HASH = 0x08,
|
1444
1474
|
dump_obj, // RUBY_T_STRUCT = 0x09,
|
1445
|
-
|
1446
|
-
//oj_dump_bignum, // RUBY_T_BIGNUM = 0x0a,
|
1475
|
+
oj_dump_bignum, // RUBY_T_BIGNUM = 0x0a,
|
1447
1476
|
dump_as_string, // RUBY_T_FILE = 0x0b,
|
1448
1477
|
dump_obj, // RUBY_T_DATA = 0x0c,
|
1449
1478
|
NULL, // RUBY_T_MATCH = 0x0d,
|
data/ext/oj/sparse.c
CHANGED
data/ext/oj/wab.c
CHANGED
@@ -148,11 +148,12 @@ dump_array(VALUE a, int depth, Out out, bool as_ok) {
|
|
148
148
|
}
|
149
149
|
|
150
150
|
static int
|
151
|
-
hash_cb(VALUE key, VALUE value,
|
151
|
+
hash_cb(VALUE key, VALUE value, VALUE ov) {
|
152
|
+
Out out = (Out)ov;
|
152
153
|
int depth = out->depth;
|
153
154
|
long size;
|
154
155
|
int rtype = rb_type(key);
|
155
|
-
|
156
|
+
|
156
157
|
if (rtype != T_SYMBOL) {
|
157
158
|
rb_raise(rb_eTypeError, "In :wab mode all Hash keys must be Symbols, not %s.\n", rb_class2name(rb_obj_class(key)));
|
158
159
|
}
|
@@ -270,7 +271,7 @@ static DumpFunc wab_funcs[] = {
|
|
270
271
|
void
|
271
272
|
oj_dump_wab_val(VALUE obj, int depth, Out out) {
|
272
273
|
int type = rb_type(obj);
|
273
|
-
|
274
|
+
|
274
275
|
if (Yes == out->opts->trace) {
|
275
276
|
oj_trace("dump", obj, __FILE__, __LINE__, depth, TraceIn);
|
276
277
|
}
|
@@ -324,7 +325,7 @@ add_value(ParseInfo pi, VALUE val) {
|
|
324
325
|
static bool
|
325
326
|
uuid_check(const char *str, int len) {
|
326
327
|
int i;
|
327
|
-
|
328
|
+
|
328
329
|
for (i = 0; i < 8; i++, str++) {
|
329
330
|
if ('x' != hex_chars[*(uint8_t*)str]) {
|
330
331
|
return false;
|
@@ -380,7 +381,7 @@ time_parse(const char *s, int len) {
|
|
380
381
|
long nsecs = 0;
|
381
382
|
int i;
|
382
383
|
time_t secs;
|
383
|
-
|
384
|
+
|
384
385
|
memset(&tm, 0, sizeof(tm));
|
385
386
|
if ('-' == *s) {
|
386
387
|
s++;
|
@@ -444,7 +445,7 @@ protect_uri(VALUE rstr) {
|
|
444
445
|
static VALUE
|
445
446
|
cstr_to_rstr(const char *str, size_t len) {
|
446
447
|
volatile VALUE v = Qnil;
|
447
|
-
|
448
|
+
|
448
449
|
if (30 == len && '-' == str[4] && '-' == str[7] && 'T' == str[10] && ':' == str[13] && ':' == str[16] && '.' == str[19] && 'Z' == str[29]) {
|
449
450
|
if (Qnil != (v = time_parse(str, (int)len))) {
|
450
451
|
return v;
|
@@ -521,7 +522,7 @@ hash_set_cstr(ParseInfo pi, Val parent, const char *str, size_t len, const char
|
|
521
522
|
static void
|
522
523
|
hash_set_num(ParseInfo pi, Val parent, NumInfo ni) {
|
523
524
|
volatile VALUE rval = Qnil;
|
524
|
-
|
525
|
+
|
525
526
|
if (ni->infinity || ni->nan) {
|
526
527
|
oj_set_error_at(pi, oj_parse_error_class, __FILE__, __LINE__, "not a number or other value");
|
527
528
|
}
|
@@ -551,7 +552,7 @@ start_array(ParseInfo pi) {
|
|
551
552
|
static void
|
552
553
|
array_append_cstr(ParseInfo pi, const char *str, size_t len, const char *orig) {
|
553
554
|
volatile VALUE rval = cstr_to_rstr(str, len);
|
554
|
-
|
555
|
+
|
555
556
|
rb_ary_push(stack_peek(&pi->stack)->val, rval);
|
556
557
|
if (Yes == pi->options.trace) {
|
557
558
|
oj_trace_parse_call("set_value", pi, __FILE__, __LINE__, rval);
|
@@ -628,4 +629,3 @@ oj_wab_parse_cstr(int argc, VALUE *argv, char *json, size_t len) {
|
|
628
629
|
|
629
630
|
return oj_pi_parse(argc, argv, &pi, json, len, true);
|
630
631
|
}
|
631
|
-
|
data/lib/oj/version.rb
CHANGED
data/test/foo.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
# encoding: UTF-8
|
3
2
|
|
4
3
|
$: << File.dirname(__FILE__)
|
5
4
|
$oj_dir = File.dirname(File.expand_path(File.dirname(__FILE__)))
|
@@ -7,161 +6,47 @@ $oj_dir = File.dirname(File.expand_path(File.dirname(__FILE__)))
|
|
7
6
|
$: << File.join($oj_dir, dir)
|
8
7
|
end
|
9
8
|
|
10
|
-
|
9
|
+
require 'json'
|
10
|
+
|
11
|
+
t = [Time.now.utc]
|
12
|
+
|
13
|
+
puts "t.to_json - #{t.to_json}"
|
14
|
+
|
15
|
+
puts "--- active support"
|
16
|
+
|
17
|
+
require 'active_support'
|
18
|
+
require "active_support/json"
|
19
|
+
|
20
|
+
ActiveSupport::JSON::Encoding.use_standard_json_time_format = false
|
21
|
+
|
22
|
+
puts "t.as_json - #{t.as_json}"
|
23
|
+
puts "t.to_json - #{t.to_json}"
|
24
|
+
|
11
25
|
require 'oj'
|
12
26
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
}
|
40
|
-
},
|
41
|
-
{
|
42
|
-
kdncg: {
|
43
|
-
lvbnt8b9ounv: {
|
44
|
-
qk: 9
|
45
|
-
}
|
46
|
-
}
|
47
|
-
}
|
48
|
-
],
|
49
|
-
jenfjbhe: {}
|
50
|
-
}
|
51
|
-
}
|
52
|
-
]
|
53
|
-
}
|
54
|
-
},
|
55
|
-
ijbh: {
|
56
|
-
jsnbrpbnunt: {
|
57
|
-
b88dibalbvp: {
|
58
|
-
mnbvd: "9uhbqlpiev"
|
59
|
-
}
|
60
|
-
},
|
61
|
-
ncnwkl: {
|
62
|
-
ksdfsf: {
|
63
|
-
mjln: "mnklkn"
|
64
|
-
},
|
65
|
-
kbrh: {
|
66
|
-
sdfn83nnalbmgnansdd: {
|
67
|
-
uijwts: {
|
68
|
-
ibha: {
|
69
|
-
uijwts: [
|
70
|
-
{
|
71
|
-
lnrbf: {
|
72
|
-
nbvtmqbhap9ebeb7btnnaw: {
|
73
|
-
ksb: "sdfksdfjsdfsb39242dnasddd",
|
74
|
-
mnm: "1293dsfnsdmfnsdfsd,fmnsd,"
|
75
|
-
}
|
76
|
-
}
|
77
|
-
}
|
78
|
-
]
|
79
|
-
}
|
80
|
-
},
|
81
|
-
kbrh: {
|
82
|
-
bo8libts: {
|
83
|
-
nag40n: {
|
84
|
-
kyen: "sdfasnc92nsn"
|
85
|
-
},
|
86
|
-
kbrh: {
|
87
|
-
nbwyu26snfcbajsdkj8: {
|
88
|
-
uijwts: {
|
89
|
-
mdfnkjsdd: {}
|
90
|
-
},
|
91
|
-
kbrh: {
|
92
|
-
kneahce: {
|
93
|
-
uijwts: {
|
94
|
-
kwnb: {
|
95
|
-
uijwts: [
|
96
|
-
{
|
97
|
-
fhfd: {
|
98
|
-
sfasdnfmasndfamsdnfajsmdf: false
|
99
|
-
}
|
100
|
-
}
|
101
|
-
],
|
102
|
-
asdfsdff: [
|
103
|
-
{
|
104
|
-
cwdf: {
|
105
|
-
sddlkfajsdkfjabskdfjalsdkfjansdkfjf: ""
|
106
|
-
}
|
107
|
-
},
|
108
|
-
{
|
109
|
-
bsdj: {
|
110
|
-
sdfsjdlfkasy8kljsfsdf83jlkjfals: true
|
111
|
-
}
|
112
|
-
}
|
113
|
-
]
|
114
|
-
}
|
115
|
-
},
|
116
|
-
kbrh: {
|
117
|
-
sdfsdfsddfk: {
|
118
|
-
uijwts: {
|
119
|
-
sdfsd: {
|
120
|
-
sdfsadf89mnlrrrqurqwvdnff: {
|
121
|
-
"kj": 8
|
122
|
-
}
|
123
|
-
}
|
124
|
-
},
|
125
|
-
kbrh: {
|
126
|
-
dkdjd: {
|
127
|
-
dfeteu: {
|
128
|
-
sdfd: "sdfasdfjlkjslrsdbb"
|
129
|
-
},
|
130
|
-
kbrh: {
|
131
|
-
sdfskjdfldk: {
|
132
|
-
buqpen: {
|
133
|
-
kjlkj: {
|
134
|
-
sdflskdjfalsdkrjalwkjfsrlfjasdf: {
|
135
|
-
sd: 0
|
136
|
-
}
|
137
|
-
}
|
138
|
-
},
|
139
|
-
kbrh: {
|
140
|
-
sdfksljdlfksdfl: {
|
141
|
-
sdfsdkfjssd: {
|
142
|
-
ksdjf: "sdflsdkfjasdkaufs;ldkfjsdlf",
|
143
|
-
sdfsdfsl: [5]
|
144
|
-
}
|
145
|
-
}
|
146
|
-
}
|
147
|
-
}
|
148
|
-
}
|
149
|
-
}
|
150
|
-
}
|
151
|
-
}
|
152
|
-
}
|
153
|
-
}
|
154
|
-
}
|
155
|
-
}
|
156
|
-
}
|
157
|
-
}
|
158
|
-
}
|
159
|
-
}
|
160
|
-
}
|
161
|
-
}
|
162
|
-
}
|
163
|
-
}
|
164
|
-
|
165
|
-
#Oj.dump(obj)
|
166
|
-
JSON.pretty_generate(obj)
|
167
|
-
#JSON.generate(obj)
|
27
|
+
t = [Time.now.utc]
|
28
|
+
|
29
|
+
puts "-----------------------"
|
30
|
+
|
31
|
+
#puts "t.as_json - #{t.as_json}"
|
32
|
+
puts "t.to_json - #{t.to_json}"
|
33
|
+
|
34
|
+
#Oj.mimic_JSON
|
35
|
+
|
36
|
+
#puts "Oj - t.as_json - #{t.as_json}"
|
37
|
+
|
38
|
+
puts "--- active support"
|
39
|
+
|
40
|
+
require 'active_support'
|
41
|
+
require "active_support/json"
|
42
|
+
|
43
|
+
ActiveSupport::JSON::Encoding.use_standard_json_time_format = false
|
44
|
+
|
45
|
+
puts "t.as_json - #{t.as_json}"
|
46
|
+
puts "t.to_json - #{t.to_json}"
|
47
|
+
|
48
|
+
puts "--- optimize"
|
49
|
+
Oj.optimize_rails
|
50
|
+
|
51
|
+
puts "t.as_json - #{t.as_json}"
|
52
|
+
puts "t.to_json - #{t.to_json}"
|
data/test/test_custom.rb
CHANGED
@@ -470,10 +470,10 @@ class CustomJuice < Minitest::Test
|
|
470
470
|
|
471
471
|
def test_time
|
472
472
|
obj = Time.now()
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
473
|
+
dump_load_dump(obj, false, :time_format => :unix, :create_id => "^o", :create_additions => true)
|
474
|
+
dump_load_dump(obj, false, :time_format => :unix_zone, :create_id => "^o", :create_additions => true)
|
475
|
+
dump_load_dump(obj, false, :time_format => :xmlschema, :create_id => "^o", :create_additions => true)
|
476
|
+
dump_load_dump(obj, false, :time_format => :ruby, :create_id => "^o", :create_additions => true)
|
477
477
|
end
|
478
478
|
|
479
479
|
def dump_and_load(obj, trace=false, options={})
|
@@ -504,4 +504,19 @@ class CustomJuice < Minitest::Test
|
|
504
504
|
loaded
|
505
505
|
end
|
506
506
|
|
507
|
+
def dump_load_dump(obj, trace=false, options={})
|
508
|
+
options = options.merge(:indent => 2, :mode => :custom)
|
509
|
+
json = Oj.dump(obj, options)
|
510
|
+
puts json if trace
|
511
|
+
|
512
|
+
loaded = Oj.load(json, options);
|
513
|
+
if obj.nil?
|
514
|
+
assert_nil(loaded)
|
515
|
+
else
|
516
|
+
json2 = Oj.dump(loaded, options)
|
517
|
+
assert_equal(json, json2)
|
518
|
+
end
|
519
|
+
loaded
|
520
|
+
end
|
521
|
+
|
507
522
|
end
|
data/test/test_rails.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# encoding: utf-8
|
3
|
+
|
4
|
+
$: << File.dirname(__FILE__)
|
5
|
+
|
6
|
+
require 'helper'
|
7
|
+
|
8
|
+
class RailsJuice < Minitest::Test
|
9
|
+
|
10
|
+
def test_bigdecimal_dump
|
11
|
+
orig = Oj.default_options
|
12
|
+
Oj.default_options = { mode: :rails, bigdecimal_as_decimal: true }
|
13
|
+
bd = BigDecimal('123')
|
14
|
+
json = Oj.dump(bd)
|
15
|
+
Oj.default_options = orig
|
16
|
+
|
17
|
+
assert_equal('0.123e3', json.downcase)
|
18
|
+
|
19
|
+
json = Oj.dump(bd, mode: :rails, bigdecimal_as_decimal: false)
|
20
|
+
assert_equal('"0.123e3"', json.downcase)
|
21
|
+
|
22
|
+
json = Oj.dump(bd, mode: :rails, bigdecimal_as_decimal: true)
|
23
|
+
assert_equal('0.123e3', json.downcase)
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
data/test/tests.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: oj
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.10.
|
4
|
+
version: 3.10.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Peter Ohler
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-01-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake-compiler
|
@@ -243,6 +243,7 @@ files:
|
|
243
243
|
- test/test_integer_range.rb
|
244
244
|
- test/test_null.rb
|
245
245
|
- test/test_object.rb
|
246
|
+
- test/test_rails.rb
|
246
247
|
- test/test_saj.rb
|
247
248
|
- test/test_scp.rb
|
248
249
|
- test/test_strict.rb
|
@@ -354,6 +355,7 @@ test_files:
|
|
354
355
|
- test/baz.rb
|
355
356
|
- test/tests_mimic_addition.rb
|
356
357
|
- test/test_writer.rb
|
358
|
+
- test/test_rails.rb
|
357
359
|
- test/perf.rb
|
358
360
|
- test/isolated/test_mimic_define.rb
|
359
361
|
- test/isolated/test_mimic_after.rb
|