oj 2.17.5 → 2.18.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -7
- data/README.md +9 -2
- data/ext/oj/dump.c +38 -19
- data/ext/oj/extconf.rb +3 -0
- data/ext/oj/object.c +13 -15
- data/ext/oj/oj.c +15 -5
- data/ext/oj/oj.h +1 -0
- data/lib/oj/version.rb +1 -1
- data/test/isolated/test_mimic_redefine.rb +15 -0
- data/test/test_compat.rb +8 -3
- data/test/test_debian.rb +1 -1
- data/test/test_file.rb +1 -1
- data/test/test_various.rb +6 -2
- metadata +76 -84
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
---
|
2
|
-
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
5
|
-
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 49295a5c6be0e45972d2cf83173fabb2db55fcc3
|
4
|
+
data.tar.gz: 645d5ec2b8214eeb596fd98cb5a9c0e1e2a9836e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 0731c01c050cc7aff03be4510be0ad026ed0a320f1fee34fb6318bcdcb5888455c13e9dfb6ec2e7b4d6436e5c04cf43a6d43ff257bb076cc1ec5b8ee5c224cc4
|
7
|
+
data.tar.gz: ce82256a18f92155498d0ee6b74c06704eb51782cd3411a3c7c2308af252386e668c43216831b32999a349cea83ff5804515314ec1ef9dfc1df36fac388c56dc
|
data/README.md
CHANGED
@@ -170,9 +170,16 @@ Oj.default_options = {:mode => :compat }
|
|
170
170
|
|
171
171
|
## Releases
|
172
172
|
|
173
|
-
**
|
173
|
+
** Release 2.18.0**
|
174
174
|
|
175
|
-
-
|
175
|
+
- Rubinius compilation fixes.
|
176
|
+
|
177
|
+
- Added a separate option for as_json instead of piggy backing on the
|
178
|
+
use_to_json. This changes the API slightly.
|
179
|
+
|
180
|
+
- Ready for Ruby 2.4.
|
181
|
+
|
182
|
+
- Thanks to faucct for fixing mimic to not redefine JSON::ParseError.
|
176
183
|
|
177
184
|
[Older release notes](http://www.ohler.com/dev/oj_misc/release_notes.html).
|
178
185
|
|
data/ext/oj/dump.c
CHANGED
@@ -1118,7 +1118,7 @@ dump_time(VALUE obj, Out out, int withZone) {
|
|
1118
1118
|
long tzsecs = NUM2LONG(rb_funcall2(obj, oj_utc_offset_id, 0, 0));
|
1119
1119
|
int zneg = (0 > tzsecs);
|
1120
1120
|
|
1121
|
-
if (0 == tzsecs &&
|
1121
|
+
if (0 == tzsecs && rb_funcall2(obj, oj_utcq_id, 0, 0)) {
|
1122
1122
|
tzsecs = 86400;
|
1123
1123
|
}
|
1124
1124
|
if (zneg) {
|
@@ -1251,7 +1251,7 @@ dump_xml_time(VALUE obj, Out out) {
|
|
1251
1251
|
}
|
1252
1252
|
#endif
|
1253
1253
|
if (0 == nsec || 0 == out->opts->sec_prec) {
|
1254
|
-
if (0 == tzsecs &&
|
1254
|
+
if (0 == tzsecs && rb_funcall2(obj, oj_utcq_id, 0, 0)) {
|
1255
1255
|
sprintf(buf, "%04d-%02d-%02dT%02d:%02d:%02dZ",
|
1256
1256
|
tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,
|
1257
1257
|
tm->tm_hour, tm->tm_min, tm->tm_sec);
|
@@ -1263,7 +1263,7 @@ dump_xml_time(VALUE obj, Out out) {
|
|
1263
1263
|
tzsign, tzhour, tzmin);
|
1264
1264
|
dump_cstr(buf, 25, 0, 0, out);
|
1265
1265
|
}
|
1266
|
-
} else if (0 == tzsecs &&
|
1266
|
+
} else if (0 == tzsecs && rb_funcall2(obj, oj_utcq_id, 0, 0)) {
|
1267
1267
|
char format[64] = "%04d-%02d-%02dT%02d:%02d:%02d.%09ldZ";
|
1268
1268
|
int len = 30;
|
1269
1269
|
|
@@ -1321,7 +1321,7 @@ static void
|
|
1321
1321
|
dump_data_comp(VALUE obj, int depth, Out out, int argc, VALUE *argv, bool as_ok) {
|
1322
1322
|
VALUE clas = rb_obj_class(obj);
|
1323
1323
|
|
1324
|
-
if (as_ok && rb_respond_to(obj, oj_to_hash_id)) {
|
1324
|
+
if (as_ok && Yes == out->opts->to_json && rb_respond_to(obj, oj_to_hash_id)) {
|
1325
1325
|
volatile VALUE h = rb_funcall(obj, oj_to_hash_id, 0);
|
1326
1326
|
|
1327
1327
|
if (T_HASH != rb_type(h)) {
|
@@ -1333,14 +1333,14 @@ dump_data_comp(VALUE obj, int depth, Out out, int argc, VALUE *argv, bool as_ok)
|
|
1333
1333
|
dump_val(h, depth, out, 0, 0, false);
|
1334
1334
|
}
|
1335
1335
|
dump_hash(h, Qundef, depth, out->opts->mode, out);
|
1336
|
-
|
1337
1336
|
} else if (Yes == out->opts->bigdec_as_num && oj_bigdecimal_class == clas) {
|
1338
1337
|
volatile VALUE rstr = rb_funcall(obj, oj_to_s_id, 0);
|
1339
1338
|
|
1340
1339
|
dump_raw(rb_string_value_ptr((VALUE*)&rstr), RSTRING_LEN(rstr), out);
|
1341
|
-
} else if (as_ok && rb_respond_to(obj, oj_as_json_id)) {
|
1340
|
+
} else if (as_ok && Yes == out->opts->as_json && rb_respond_to(obj, oj_as_json_id)) {
|
1342
1341
|
volatile VALUE aj;
|
1343
1342
|
|
1343
|
+
#if HAS_METHOD_ARITY
|
1344
1344
|
// Some classes elect to not take an options argument so check the arity
|
1345
1345
|
// of as_json.
|
1346
1346
|
switch (rb_obj_method_arity(obj, oj_as_json_id)) {
|
@@ -1361,6 +1361,9 @@ dump_data_comp(VALUE obj, int depth, Out out, int argc, VALUE *argv, bool as_ok)
|
|
1361
1361
|
aj = rb_funcall2(obj, oj_as_json_id, argc, argv);
|
1362
1362
|
break;
|
1363
1363
|
}
|
1364
|
+
#else
|
1365
|
+
aj = rb_funcall2(obj, oj_as_json_id, argc, argv);
|
1366
|
+
#endif
|
1364
1367
|
// Catch the obvious brain damaged recursive dumping.
|
1365
1368
|
if (aj == obj) {
|
1366
1369
|
volatile VALUE rstr = rb_funcall(obj, oj_to_s_id, 0);
|
@@ -1451,7 +1454,7 @@ dump_data_obj(VALUE obj, int depth, Out out) {
|
|
1451
1454
|
|
1452
1455
|
static void
|
1453
1456
|
dump_obj_comp(VALUE obj, int depth, Out out, int argc, VALUE *argv, bool as_ok) {
|
1454
|
-
if (as_ok && rb_respond_to(obj, oj_to_hash_id)) {
|
1457
|
+
if (as_ok && Yes == out->opts->to_json && rb_respond_to(obj, oj_to_hash_id)) {
|
1455
1458
|
volatile VALUE h = rb_funcall(obj, oj_to_hash_id, 0);
|
1456
1459
|
|
1457
1460
|
if (T_HASH != rb_type(h)) {
|
@@ -1464,9 +1467,10 @@ dump_obj_comp(VALUE obj, int depth, Out out, int argc, VALUE *argv, bool as_ok)
|
|
1464
1467
|
} else {
|
1465
1468
|
dump_hash(h, Qundef, depth, out->opts->mode, out);
|
1466
1469
|
}
|
1467
|
-
} else if (as_ok && rb_respond_to(obj, oj_as_json_id)) {
|
1470
|
+
} else if (as_ok && Yes == out->opts->as_json && rb_respond_to(obj, oj_as_json_id)) {
|
1468
1471
|
volatile VALUE aj;
|
1469
1472
|
|
1473
|
+
#if HAS_METHOD_ARITY
|
1470
1474
|
// Some classes elect to not take an options argument so check the arity
|
1471
1475
|
// of as_json.
|
1472
1476
|
switch (rb_obj_method_arity(obj, oj_as_json_id)) {
|
@@ -1487,6 +1491,9 @@ dump_obj_comp(VALUE obj, int depth, Out out, int argc, VALUE *argv, bool as_ok)
|
|
1487
1491
|
aj = rb_funcall2(obj, oj_as_json_id, argc, argv);
|
1488
1492
|
break;
|
1489
1493
|
}
|
1494
|
+
#else
|
1495
|
+
aj = rb_funcall2(obj, oj_as_json_id, argc, argv);
|
1496
|
+
#endif
|
1490
1497
|
// Catch the obvious brain damaged recursive dumping.
|
1491
1498
|
if (aj == obj) {
|
1492
1499
|
volatile VALUE rstr = rb_funcall(obj, oj_to_s_id, 0);
|
@@ -1774,7 +1781,7 @@ dump_obj_attrs(VALUE obj, VALUE clas, slot_t id, int depth, Out out) {
|
|
1774
1781
|
}
|
1775
1782
|
#endif
|
1776
1783
|
#if HAS_EXCEPTION_MAGIC
|
1777
|
-
if (
|
1784
|
+
if (rb_obj_is_kind_of(obj, rb_eException)) {
|
1778
1785
|
volatile VALUE rv;
|
1779
1786
|
|
1780
1787
|
if (',' != *(out->cur - 1)) {
|
@@ -1816,7 +1823,7 @@ dump_obj_attrs(VALUE obj, VALUE clas, slot_t id, int depth, Out out) {
|
|
1816
1823
|
|
1817
1824
|
static void
|
1818
1825
|
dump_struct_comp(VALUE obj, int depth, Out out, int argc, VALUE *argv, bool as_ok) {
|
1819
|
-
if (as_ok && rb_respond_to(obj, oj_to_hash_id)) {
|
1826
|
+
if (as_ok && Yes == out->opts->to_json && rb_respond_to(obj, oj_to_hash_id)) {
|
1820
1827
|
volatile VALUE h = rb_funcall(obj, oj_to_hash_id, 0);
|
1821
1828
|
|
1822
1829
|
if (T_HASH != rb_type(h)) {
|
@@ -1828,9 +1835,10 @@ dump_struct_comp(VALUE obj, int depth, Out out, int argc, VALUE *argv, bool as_o
|
|
1828
1835
|
dump_val(h, depth, out, 0, 0, false);
|
1829
1836
|
}
|
1830
1837
|
dump_hash(h, Qundef, depth, out->opts->mode, out);
|
1831
|
-
} else if (as_ok && rb_respond_to(obj, oj_as_json_id)) {
|
1838
|
+
} else if (as_ok && Yes == out->opts->as_json && rb_respond_to(obj, oj_as_json_id)) {
|
1832
1839
|
volatile VALUE aj;
|
1833
1840
|
|
1841
|
+
#if HAS_METHOD_ARITY
|
1834
1842
|
// Some classes elect to not take an options argument so check the arity
|
1835
1843
|
// of as_json.
|
1836
1844
|
switch (rb_obj_method_arity(obj, oj_as_json_id)) {
|
@@ -1851,6 +1859,9 @@ dump_struct_comp(VALUE obj, int depth, Out out, int argc, VALUE *argv, bool as_o
|
|
1851
1859
|
aj = rb_funcall2(obj, oj_as_json_id, argc, argv);
|
1852
1860
|
break;
|
1853
1861
|
}
|
1862
|
+
#else
|
1863
|
+
aj = rb_funcall2(obj, oj_as_json_id, argc, argv);
|
1864
|
+
#endif
|
1854
1865
|
// Catch the obvious brain damaged recursive dumping.
|
1855
1866
|
if (aj == obj) {
|
1856
1867
|
volatile VALUE rstr = rb_funcall(obj, oj_to_s_id, 0);
|
@@ -1899,6 +1910,7 @@ dump_struct_obj(VALUE obj, int depth, Out out) {
|
|
1899
1910
|
*out->cur++ = '"';
|
1900
1911
|
*out->cur++ = ':';
|
1901
1912
|
*out->cur++ = '[';
|
1913
|
+
#if HAS_STRUCT_MEMBERS
|
1902
1914
|
if ('#' == *class_name) {
|
1903
1915
|
VALUE ma = rb_struct_s_members(clas);
|
1904
1916
|
const char *name;
|
@@ -1922,6 +1934,9 @@ dump_struct_obj(VALUE obj, int depth, Out out) {
|
|
1922
1934
|
}
|
1923
1935
|
*out->cur++ = ']';
|
1924
1936
|
} else {
|
1937
|
+
#else
|
1938
|
+
if (true) {
|
1939
|
+
#endif
|
1925
1940
|
fill_indent(out, d3);
|
1926
1941
|
*out->cur++ = '"';
|
1927
1942
|
memcpy(out->cur, class_name, len);
|
@@ -1932,17 +1947,21 @@ dump_struct_obj(VALUE obj, int depth, Out out) {
|
|
1932
1947
|
size = d3 * out->indent + 2;
|
1933
1948
|
#ifdef RSTRUCT_LEN
|
1934
1949
|
{
|
1935
|
-
|
1936
|
-
|
1937
|
-
#
|
1938
|
-
|
1939
|
-
#
|
1940
|
-
|
1950
|
+
VALUE v;
|
1951
|
+
int cnt;
|
1952
|
+
#if UNIFY_FIXNUM_AND_BIGNUM
|
1953
|
+
cnt = (int)NUM2LONG(RSTRUCT_LEN(obj));
|
1954
|
+
#else // UNIFY_FIXNUM_AND_INTEGER
|
1955
|
+
cnt = (int)RSTRUCT_LEN(obj);
|
1956
|
+
#endif // UNIFY_FIXNUM_AND_INTEGER
|
1957
|
+
|
1958
|
+
for (i = 0; i < cnt; i++) {
|
1959
|
+
v = RSTRUCT_GET(obj, i);
|
1941
1960
|
if (out->end - out->cur <= (long)size) {
|
1942
1961
|
grow(out, size);
|
1943
1962
|
}
|
1944
1963
|
fill_indent(out, d3);
|
1945
|
-
dump_val(
|
1964
|
+
dump_val(v, d3, out, 0, 0, true);
|
1946
1965
|
*out->cur++ = ',';
|
1947
1966
|
}
|
1948
1967
|
}
|
@@ -1957,7 +1976,7 @@ dump_struct_obj(VALUE obj, int depth, Out out) {
|
|
1957
1976
|
grow(out, size);
|
1958
1977
|
}
|
1959
1978
|
fill_indent(out, d3);
|
1960
|
-
dump_val(rb_struct_aref(obj, INT2FIX(i)), d3, out, 0, 0);
|
1979
|
+
dump_val(rb_struct_aref(obj, INT2FIX(i)), d3, out, 0, 0, true);
|
1961
1980
|
*out->cur++ = ',';
|
1962
1981
|
}
|
1963
1982
|
}
|
data/ext/oj/extconf.rb
CHANGED
@@ -35,6 +35,9 @@ dflags = {
|
|
35
35
|
'DATETIME_1_8' => ('ruby' == type && ('1' == version[0] && '8' == version[1])) ? 1 : 0,
|
36
36
|
'NO_TIME_ROUND_PAD' => ('rubinius' == type) ? 1 : 0,
|
37
37
|
'HAS_DATA_OBJECT_WRAP' => ('ruby' == type && '2' == version[0] && '3' <= version[1]) ? 1 : 0,
|
38
|
+
'HAS_METHOD_ARITY' => ('rubinius' == type) ? 0 : 1,
|
39
|
+
'HAS_STRUCT_MEMBERS' => ('rubinius' == type) ? 0 : 1,
|
40
|
+
'UNIFY_FIXNUM_AND_BIGNUM' => ('ruby' == type && '2' == version[0] && '4' <= version[1]) ? 1 : 0,
|
38
41
|
}
|
39
42
|
# This is a monster hack to get around issues with 1.9.3-p0 on CentOS 5.4. SO
|
40
43
|
# some reason math.h and string.h contents are not processed. Might be a
|
data/ext/oj/object.c
CHANGED
@@ -390,7 +390,8 @@ hat_value(ParseInfo pi, Val parent, const char *key, size_t klen, volatile VALUE
|
|
390
390
|
if (2 == klen && 'u' == key[1]) {
|
391
391
|
volatile VALUE sc;
|
392
392
|
volatile VALUE e1;
|
393
|
-
|
393
|
+
int slen;
|
394
|
+
|
394
395
|
if (0 == len) {
|
395
396
|
oj_set_error_at(pi, oj_parse_error_class, __FILE__, __LINE__, "Invalid struct data");
|
396
397
|
return 1;
|
@@ -415,27 +416,24 @@ hat_value(ParseInfo pi, Val parent, const char *key, size_t klen, volatile VALUE
|
|
415
416
|
parent->val = rb_obj_alloc(sc);
|
416
417
|
// If the JSON array has more entries than the struct class allows, we record an error.
|
417
418
|
#ifdef RSTRUCT_LEN
|
419
|
+
#if UNIFY_FIXNUM_AND_BIGNUM
|
420
|
+
slen = (int)NUM2LONG(RSTRUCT_LEN(parent->val));
|
421
|
+
#else // UNIFY_FIXNUM_AND_INTEGER
|
422
|
+
slen = (int)RSTRUCT_LEN(parent->val);
|
423
|
+
#endif // UNIFY_FIXNUM_AND_INTEGER
|
424
|
+
#else
|
425
|
+
slen = FIX2INT(rb_funcall2(parent->val, oj_length_id, 0, 0));
|
426
|
+
#endif
|
418
427
|
// MRI >= 1.9
|
419
|
-
if (len - 1 >
|
428
|
+
if (len - 1 > slen) {
|
420
429
|
oj_set_error_at(pi, oj_parse_error_class, __FILE__, __LINE__, "Invalid struct data");
|
421
430
|
} else {
|
422
|
-
MEMCPY(RSTRUCT_PTR(parent->val), RARRAY_PTR(value) + 1, VALUE, len - 1);
|
423
|
-
}
|
424
|
-
#else
|
425
|
-
{
|
426
|
-
// MRI < 1.9 or Rubinius
|
427
|
-
int slen = FIX2INT(rb_funcall2(parent->val, oj_length_id, 0, 0));
|
428
431
|
int i;
|
429
432
|
|
430
|
-
|
431
|
-
|
432
|
-
} else {
|
433
|
-
for (i = 0; i < slen; i++) {
|
434
|
-
rb_struct_aset(parent->val, INT2FIX(i), RARRAY_PTR(value)[i + 1]);
|
435
|
-
}
|
433
|
+
for (i = 0; i < slen; i++) {
|
434
|
+
rb_struct_aset(parent->val, INT2FIX(i), RARRAY_PTR(value)[i + 1]);
|
436
435
|
}
|
437
436
|
}
|
438
|
-
#endif
|
439
437
|
return 1;
|
440
438
|
} else if (3 <= klen && '#' == key[1]) {
|
441
439
|
volatile VALUE *a;
|
data/ext/oj/oj.c
CHANGED
@@ -142,6 +142,7 @@ static VALUE symbol_keys_sym;
|
|
142
142
|
static VALUE time_format_sym;
|
143
143
|
static VALUE unix_sym;
|
144
144
|
static VALUE unix_zone_sym;
|
145
|
+
static VALUE use_as_json_sym;
|
145
146
|
static VALUE use_to_json_sym;
|
146
147
|
static VALUE word_sym;
|
147
148
|
static VALUE xmlschema_sym;
|
@@ -180,7 +181,8 @@ struct _Options oj_default_options = {
|
|
180
181
|
UnixZTime, // time_format
|
181
182
|
Yes, // bigdec_as_num
|
182
183
|
AutoDec, // bigdec_load
|
183
|
-
|
184
|
+
No, // to_json
|
185
|
+
No, // as_json
|
184
186
|
No, // nilnil
|
185
187
|
Yes, // allow_gc
|
186
188
|
Yes, // quirks_mode
|
@@ -227,6 +229,7 @@ static VALUE define_mimic_json(int argc, VALUE *argv, VALUE self);
|
|
227
229
|
* - second_precision: [Fixnum|nil] number of digits after the decimal when dumping the seconds portion of time
|
228
230
|
* - float_precision: [Fixnum|nil] number of digits of precision when dumping floats, 0 indicates use Ruby
|
229
231
|
* - use_to_json: [true|false|nil] call to_json() methods on dump, default is false
|
232
|
+
* - use_as_json: [true|false|nil] call as_json() methods on dump, default is false
|
230
233
|
* - nilnil: [true|false|nil] if true a nil input to load will return nil and not raise an Exception
|
231
234
|
* - allow_gc: [true|false|nil] allow or prohibit GC during parsing, default is true (allow)
|
232
235
|
* - quirks_mode: [true,|false|nil] Allow single JSON values instead of documents, default is true (allow)
|
@@ -257,6 +260,7 @@ get_def_opts(VALUE self) {
|
|
257
260
|
rb_hash_aset(opts, symbol_keys_sym, (Yes == oj_default_options.sym_key) ? Qtrue : ((No == oj_default_options.sym_key) ? Qfalse : Qnil));
|
258
261
|
rb_hash_aset(opts, bigdecimal_as_decimal_sym, (Yes == oj_default_options.bigdec_as_num) ? Qtrue : ((No == oj_default_options.bigdec_as_num) ? Qfalse : Qnil));
|
259
262
|
rb_hash_aset(opts, use_to_json_sym, (Yes == oj_default_options.to_json) ? Qtrue : ((No == oj_default_options.to_json) ? Qfalse : Qnil));
|
263
|
+
rb_hash_aset(opts, use_as_json_sym, (Yes == oj_default_options.as_json) ? Qtrue : ((No == oj_default_options.as_json) ? Qfalse : Qnil));
|
260
264
|
rb_hash_aset(opts, nilnil_sym, (Yes == oj_default_options.nilnil) ? Qtrue : ((No == oj_default_options.nilnil) ? Qfalse : Qnil));
|
261
265
|
rb_hash_aset(opts, allow_gc_sym, (Yes == oj_default_options.allow_gc) ? Qtrue : ((No == oj_default_options.allow_gc) ? Qfalse : Qnil));
|
262
266
|
rb_hash_aset(opts, quirks_mode_sym, (Yes == oj_default_options.quirks_mode) ? Qtrue : ((No == oj_default_options.quirks_mode) ? Qfalse : Qnil));
|
@@ -341,6 +345,7 @@ get_def_opts(VALUE self) {
|
|
341
345
|
* @param [Fixnum|nil] :second_precision number of digits after the decimal when dumping the seconds portion of time
|
342
346
|
* @param [Fixnum|nil] :float_precision number of digits of precision when dumping floats, 0 indicates use Ruby
|
343
347
|
* @param [true|false|nil] :use_to_json call to_json() methods on dump, default is false
|
348
|
+
* @param [true|false|nil] :use_as_json call as_json() methods on dump, default is false
|
344
349
|
* @param [true|false|nil] :nilnil if true a nil input to load will return nil and not raise an Exception
|
345
350
|
* @param [true|false|nil] :allow_gc allow or prohibit GC during parsing, default is true (allow)
|
346
351
|
* @param [true|false|nil] :quirks_mode allow single JSON values instead of documents, default is true (allow)
|
@@ -371,6 +376,7 @@ oj_parse_options(VALUE ropts, Options copts) {
|
|
371
376
|
{ class_cache_sym, &copts->class_cache },
|
372
377
|
{ bigdecimal_as_decimal_sym, &copts->bigdec_as_num },
|
373
378
|
{ use_to_json_sym, &copts->to_json },
|
379
|
+
{ use_as_json_sym, &copts->as_json },
|
374
380
|
{ nilnil_sym, &copts->nilnil },
|
375
381
|
{ allow_gc_sym, &copts->allow_gc },
|
376
382
|
{ quirks_mode_sym, &copts->quirks_mode },
|
@@ -1908,6 +1914,7 @@ static struct _Options mimic_object_to_json_options = {
|
|
1908
1914
|
No, // bigdec_as_num
|
1909
1915
|
FloatDec, // bigdec_load
|
1910
1916
|
No, // to_json
|
1917
|
+
Yes, // as_json
|
1911
1918
|
Yes, // nilnil
|
1912
1919
|
Yes, // allow_gc
|
1913
1920
|
Yes, // quirks_mode
|
@@ -2049,13 +2056,15 @@ define_mimic_json(int argc, VALUE *argv, VALUE self) {
|
|
2049
2056
|
symbolize_names_sym = ID2SYM(rb_intern("symbolize_names")); rb_gc_register_address(&symbolize_names_sym);
|
2050
2057
|
|
2051
2058
|
if (rb_const_defined_at(mimic, rb_intern("JSONError"))) {
|
2052
|
-
|
2059
|
+
json_error = rb_const_get(mimic, rb_intern("JSONError"));
|
2060
|
+
} else {
|
2061
|
+
json_error = rb_define_class_under(mimic, "JSONError", rb_eStandardError);
|
2053
2062
|
}
|
2054
|
-
json_error = rb_define_class_under(mimic, "JSONError", rb_eStandardError);
|
2055
2063
|
if (rb_const_defined_at(mimic, rb_intern("ParserError"))) {
|
2056
|
-
|
2064
|
+
json_parser_error_class = rb_const_get(mimic, rb_intern("ParserError"));
|
2065
|
+
} else {
|
2066
|
+
json_parser_error_class = rb_define_class_under(mimic, "ParserError", json_error);
|
2057
2067
|
}
|
2058
|
-
json_parser_error_class = rb_define_class_under(mimic, "ParserError", json_error);
|
2059
2068
|
|
2060
2069
|
if (!rb_const_defined_at(mimic, rb_intern("State"))) {
|
2061
2070
|
rb_define_class_under(mimic, "State", rb_cObject);
|
@@ -2262,6 +2271,7 @@ void Init_oj() {
|
|
2262
2271
|
time_format_sym = ID2SYM(rb_intern("time_format")); rb_gc_register_address(&time_format_sym);
|
2263
2272
|
unix_sym = ID2SYM(rb_intern("unix")); rb_gc_register_address(&unix_sym);
|
2264
2273
|
unix_zone_sym = ID2SYM(rb_intern("unix_zone")); rb_gc_register_address(&unix_zone_sym);
|
2274
|
+
use_as_json_sym = ID2SYM(rb_intern("use_as_json")); rb_gc_register_address(&use_as_json_sym);
|
2265
2275
|
use_to_json_sym = ID2SYM(rb_intern("use_to_json")); rb_gc_register_address(&use_to_json_sym);
|
2266
2276
|
word_sym = ID2SYM(rb_intern("word")); rb_gc_register_address(&word_sym);
|
2267
2277
|
xmlschema_sym = ID2SYM(rb_intern("xmlschema")); rb_gc_register_address(&xmlschema_sym);
|
data/ext/oj/oj.h
CHANGED
@@ -154,6 +154,7 @@ typedef struct _Options {
|
|
154
154
|
char bigdec_as_num; // YesNo
|
155
155
|
char bigdec_load; // BigLoad
|
156
156
|
char to_json; // YesNo
|
157
|
+
char as_json; // YesNo
|
157
158
|
char nilnil; // YesNo
|
158
159
|
char allow_gc; // allow GC during parse
|
159
160
|
char quirks_mode; // allow single JSON values instead of documents
|
data/lib/oj/version.rb
CHANGED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# encoding: UTF-8
|
3
|
+
|
4
|
+
$: << File.join(File.dirname(__FILE__), '..')
|
5
|
+
|
6
|
+
require 'helper'
|
7
|
+
|
8
|
+
class MimicRedefine < Minitest::Test
|
9
|
+
def test_mimic_redefine
|
10
|
+
require 'json'
|
11
|
+
parser_error = JSON::ParserError
|
12
|
+
Oj.mimic_JSON
|
13
|
+
assert_equal(parser_error, JSON::ParserError)
|
14
|
+
end
|
15
|
+
end # MimicSingle
|
data/test/test_compat.rb
CHANGED
@@ -331,18 +331,20 @@ class CompatJuice < Minitest::Test
|
|
331
331
|
|
332
332
|
def test_json_object_compat
|
333
333
|
obj = Jeez.new(true, 58)
|
334
|
-
Oj.default_options = { :mode => :compat, :use_to_json => true }
|
334
|
+
Oj.default_options = { :mode => :compat, :use_as_json => true, :use_to_json => true }
|
335
335
|
dump_and_load(obj, false)
|
336
336
|
end
|
337
337
|
|
338
338
|
def test_json_module_object
|
339
|
+
Oj.default_options = { :mode => :compat, :use_as_json => true, :use_to_json => true }
|
339
340
|
obj = One::Two::Three::Deep.new()
|
340
341
|
dump_and_load(obj, false)
|
341
342
|
end
|
342
343
|
|
343
344
|
def test_json_object_create_id
|
345
|
+
Oj.default_options = { :mode => :compat, :use_as_json => false, :use_to_json => false }
|
344
346
|
expected = Jeez.new(true, 58)
|
345
|
-
json = Oj.dump(expected, :indent => 2, :mode => :compat, :use_to_json => true)
|
347
|
+
json = Oj.dump(expected, :indent => 2, :mode => :compat, :use_to_json => true, :use_as_json => true)
|
346
348
|
obj = Oj.compat_load(json)
|
347
349
|
assert_equal(expected, obj)
|
348
350
|
end
|
@@ -359,6 +361,7 @@ class CompatJuice < Minitest::Test
|
|
359
361
|
end
|
360
362
|
|
361
363
|
def test_json_object_create_cache
|
364
|
+
Oj.default_options = { :mode => :compat, :use_as_json => true, :use_to_json => true }
|
362
365
|
expected = Jeez.new(true, 58)
|
363
366
|
json = Oj.dump(expected, :indent => 2, :mode => :compat, :use_to_json => true)
|
364
367
|
obj = Oj.compat_load(json, :class_cache => true)
|
@@ -368,14 +371,16 @@ class CompatJuice < Minitest::Test
|
|
368
371
|
end
|
369
372
|
|
370
373
|
def test_json_object_create_id_other
|
374
|
+
Oj.default_options = { :mode => :compat, :use_as_json => false, :use_to_json => false }
|
371
375
|
expected = Jeez.new(true, 58)
|
372
|
-
json = Oj.dump(expected, :indent => 2, :mode => :compat, :
|
376
|
+
json = Oj.dump(expected, :indent => 2, :mode => :compat, :use_as_json => true)
|
373
377
|
json.gsub!('json_class', '_class_')
|
374
378
|
obj = Oj.compat_load(json, :create_id => "_class_")
|
375
379
|
assert_equal(expected, obj)
|
376
380
|
end
|
377
381
|
|
378
382
|
def test_json_object_create_deep
|
383
|
+
Oj.default_options = { :mode => :compat, :use_as_json => true, :use_to_json => true }
|
379
384
|
expected = One::Two::Three::Deep.new()
|
380
385
|
json = Oj.dump(expected, :indent => 2, :mode => :compat)
|
381
386
|
obj = Oj.compat_load(json)
|
data/test/test_debian.rb
CHANGED
@@ -36,7 +36,7 @@ class DebJuice < Minitest::Test
|
|
36
36
|
end
|
37
37
|
|
38
38
|
def test_as_json_object_compat_hash_cached
|
39
|
-
Oj.default_options = { :mode => :compat, :class_cache => true, :
|
39
|
+
Oj.default_options = { :mode => :compat, :class_cache => true, :use_as_json => true }
|
40
40
|
obj = Orange.new(true, 58)
|
41
41
|
json = Oj.dump(obj, :indent => 2)
|
42
42
|
assert(!json.nil?)
|
data/test/test_file.rb
CHANGED
@@ -157,7 +157,7 @@ class FileJuice < Minitest::Test
|
|
157
157
|
end
|
158
158
|
|
159
159
|
def test_as_json_object_compat_hash
|
160
|
-
Oj.default_options = { :mode => :compat, :
|
160
|
+
Oj.default_options = { :mode => :compat, :use_as_json => true }
|
161
161
|
obj = Orange.new(true, 58)
|
162
162
|
json = Oj.dump(obj, :indent => 2)
|
163
163
|
assert(!json.nil?)
|
data/test/test_various.rb
CHANGED
@@ -126,6 +126,7 @@ class Juice < Minitest::Test
|
|
126
126
|
:symbol_keys=>true,
|
127
127
|
:bigdecimal_as_decimal=>false,
|
128
128
|
:use_to_json=>false,
|
129
|
+
:use_as_json=>false,
|
129
130
|
:nilnil=>true,
|
130
131
|
:allow_gc=>false,
|
131
132
|
:quirks_mode=>false,
|
@@ -759,6 +760,7 @@ class Juice < Minitest::Test
|
|
759
760
|
assert_equal('null', json)
|
760
761
|
end
|
761
762
|
def test_to_hash_object_compat
|
763
|
+
Oj.default_options = { :use_to_json => true }
|
762
764
|
obj = Jazz.new(true, 58)
|
763
765
|
json = Oj.dump(obj, :mode => :compat, :indent => 2)
|
764
766
|
h = Oj.load(json, :mode => :strict)
|
@@ -802,7 +804,7 @@ class Juice < Minitest::Test
|
|
802
804
|
end
|
803
805
|
|
804
806
|
def test_as_json_object_compat_hash
|
805
|
-
Oj.default_options = { :mode => :compat, :
|
807
|
+
Oj.default_options = { :mode => :compat, :use_as_json => true }
|
806
808
|
obj = Orange.new(true, 58)
|
807
809
|
json = Oj.dump(obj, :indent => 2)
|
808
810
|
assert(!json.nil?)
|
@@ -810,7 +812,7 @@ class Juice < Minitest::Test
|
|
810
812
|
end
|
811
813
|
|
812
814
|
def test_as_json_object_compat_non_hash
|
813
|
-
Oj.default_options = { :mode => :compat, :
|
815
|
+
Oj.default_options = { :mode => :compat, :use_as_json => true }
|
814
816
|
obj = Melon.new(true, 58)
|
815
817
|
json = Oj.dump(obj, :indent => 2)
|
816
818
|
assert_equal(%{"true 58"}, json)
|
@@ -942,6 +944,7 @@ class Juice < Minitest::Test
|
|
942
944
|
assert_equal('null', json)
|
943
945
|
end
|
944
946
|
def test_range_compat
|
947
|
+
Oj.default_options = { :use_to_json => true }
|
945
948
|
json = Oj.dump(1..7, :mode => :compat)
|
946
949
|
h = Oj.load(json, :mode => :strict)
|
947
950
|
assert_equal({'begin' => 1, 'end' => 7, 'exclude_end' => false}, h)
|
@@ -1022,6 +1025,7 @@ class Juice < Minitest::Test
|
|
1022
1025
|
assert_equal(orig.to_f, bg)
|
1023
1026
|
end
|
1024
1027
|
def test_bigdecimal_compat_as_json
|
1028
|
+
Oj.default_options = { :use_as_json => true }
|
1025
1029
|
orig = BigDecimal.new('80.51')
|
1026
1030
|
BigDecimal.send(:define_method, :as_json) do
|
1027
1031
|
%{this is big}
|
metadata
CHANGED
@@ -1,65 +1,55 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: oj
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 2.18.0
|
5
5
|
platform: ruby
|
6
|
-
authors:
|
6
|
+
authors:
|
7
7
|
- Peter Ohler
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
|
12
|
-
|
13
|
-
|
11
|
+
|
12
|
+
date: 2016-11-26 00:00:00 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
14
15
|
name: rake-compiler
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - "~>"
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '0.9'
|
20
|
-
type: :development
|
21
16
|
prerelease: false
|
22
|
-
|
23
|
-
requirements:
|
24
|
-
- -
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version:
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: minitest
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - "~>"
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '5'
|
17
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: "0.9"
|
34
22
|
type: :development
|
23
|
+
version_requirements: *id001
|
24
|
+
- !ruby/object:Gem::Dependency
|
25
|
+
name: minitest
|
35
26
|
prerelease: false
|
36
|
-
|
37
|
-
requirements:
|
38
|
-
- -
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version:
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: rails
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - "~>"
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: '4'
|
27
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
28
|
+
requirements:
|
29
|
+
- - ~>
|
30
|
+
- !ruby/object:Gem::Version
|
31
|
+
version: "5"
|
48
32
|
type: :development
|
33
|
+
version_requirements: *id002
|
34
|
+
- !ruby/object:Gem::Dependency
|
35
|
+
name: rails
|
49
36
|
prerelease: false
|
50
|
-
|
51
|
-
requirements:
|
52
|
-
- -
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version:
|
55
|
-
|
37
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ~>
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: "4"
|
42
|
+
type: :development
|
43
|
+
version_requirements: *id003
|
44
|
+
description: "The fastest JSON parser and object serializer. "
|
56
45
|
email: peter@ohler.com
|
57
46
|
executables: []
|
58
|
-
|
47
|
+
|
48
|
+
extensions:
|
59
49
|
- ext/oj/extconf.rb
|
60
|
-
extra_rdoc_files:
|
50
|
+
extra_rdoc_files:
|
61
51
|
- README.md
|
62
|
-
files:
|
52
|
+
files:
|
63
53
|
- LICENSE
|
64
54
|
- README.md
|
65
55
|
- ext/oj/buf.h
|
@@ -127,6 +117,7 @@ files:
|
|
127
117
|
- test/isolated/test_mimic_rails_after.rb
|
128
118
|
- test/isolated/test_mimic_rails_before.rb
|
129
119
|
- test/isolated/test_mimic_rails_datetime.rb
|
120
|
+
- test/isolated/test_mimic_redefine.rb
|
130
121
|
- test/mod.rb
|
131
122
|
- test/perf.rb
|
132
123
|
- test/perf_compat.rb
|
@@ -169,32 +160,33 @@ files:
|
|
169
160
|
- test/test_writer.rb
|
170
161
|
- test/write_timebars.rb
|
171
162
|
homepage: http://www.ohler.com/oj
|
172
|
-
licenses:
|
163
|
+
licenses:
|
173
164
|
- MIT
|
174
165
|
metadata: {}
|
166
|
+
|
175
167
|
post_install_message:
|
176
|
-
rdoc_options:
|
177
|
-
-
|
168
|
+
rdoc_options:
|
169
|
+
- --main
|
178
170
|
- README.md
|
179
|
-
require_paths:
|
171
|
+
require_paths:
|
180
172
|
- lib
|
181
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
182
|
-
requirements:
|
183
|
-
-
|
184
|
-
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
version: '0'
|
173
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
174
|
+
requirements:
|
175
|
+
- &id004
|
176
|
+
- ">="
|
177
|
+
- !ruby/object:Gem::Version
|
178
|
+
version: "0"
|
179
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
180
|
+
requirements:
|
181
|
+
- *id004
|
191
182
|
requirements: []
|
183
|
+
|
192
184
|
rubyforge_project: oj
|
193
|
-
rubygems_version: 2.
|
185
|
+
rubygems_version: 2.2.2
|
194
186
|
signing_key:
|
195
187
|
specification_version: 4
|
196
188
|
summary: A fast JSON parser and serializer.
|
197
|
-
test_files:
|
189
|
+
test_files:
|
198
190
|
- test/_test_active.rb
|
199
191
|
- test/_test_active_mimic.rb
|
200
192
|
- test/_test_mimic_rails.rb
|
@@ -210,15 +202,6 @@ test_files:
|
|
210
202
|
- test/foo.rb
|
211
203
|
- test/helper.rb
|
212
204
|
- test/io.rb
|
213
|
-
- test/isolated/shared.rb
|
214
|
-
- test/isolated/test_mimic_after.rb
|
215
|
-
- test/isolated/test_mimic_alone.rb
|
216
|
-
- test/isolated/test_mimic_as_json.rb
|
217
|
-
- test/isolated/test_mimic_before.rb
|
218
|
-
- test/isolated/test_mimic_define.rb
|
219
|
-
- test/isolated/test_mimic_rails_after.rb
|
220
|
-
- test/isolated/test_mimic_rails_before.rb
|
221
|
-
- test/isolated/test_mimic_rails_datetime.rb
|
222
205
|
- test/mod.rb
|
223
206
|
- test/perf.rb
|
224
207
|
- test/perf_compat.rb
|
@@ -231,18 +214,6 @@ test_files:
|
|
231
214
|
- test/perf_strict.rb
|
232
215
|
- test/rails.rb
|
233
216
|
- test/russian.rb
|
234
|
-
- test/sample/change.rb
|
235
|
-
- test/sample/dir.rb
|
236
|
-
- test/sample/doc.rb
|
237
|
-
- test/sample/file.rb
|
238
|
-
- test/sample/group.rb
|
239
|
-
- test/sample/hasprops.rb
|
240
|
-
- test/sample/layer.rb
|
241
|
-
- test/sample/line.rb
|
242
|
-
- test/sample/oval.rb
|
243
|
-
- test/sample/rect.rb
|
244
|
-
- test/sample/shape.rb
|
245
|
-
- test/sample/text.rb
|
246
217
|
- test/sample.rb
|
247
218
|
- test/sample_json.rb
|
248
219
|
- test/struct.rb
|
@@ -260,4 +231,25 @@ test_files:
|
|
260
231
|
- test/test_various.rb
|
261
232
|
- test/test_writer.rb
|
262
233
|
- test/write_timebars.rb
|
263
|
-
|
234
|
+
- test/isolated/shared.rb
|
235
|
+
- test/isolated/test_mimic_after.rb
|
236
|
+
- test/isolated/test_mimic_alone.rb
|
237
|
+
- test/isolated/test_mimic_as_json.rb
|
238
|
+
- test/isolated/test_mimic_before.rb
|
239
|
+
- test/isolated/test_mimic_define.rb
|
240
|
+
- test/isolated/test_mimic_rails_after.rb
|
241
|
+
- test/isolated/test_mimic_rails_before.rb
|
242
|
+
- test/isolated/test_mimic_rails_datetime.rb
|
243
|
+
- test/isolated/test_mimic_redefine.rb
|
244
|
+
- test/sample/change.rb
|
245
|
+
- test/sample/dir.rb
|
246
|
+
- test/sample/doc.rb
|
247
|
+
- test/sample/file.rb
|
248
|
+
- test/sample/group.rb
|
249
|
+
- test/sample/hasprops.rb
|
250
|
+
- test/sample/layer.rb
|
251
|
+
- test/sample/line.rb
|
252
|
+
- test/sample/oval.rb
|
253
|
+
- test/sample/rect.rb
|
254
|
+
- test/sample/shape.rb
|
255
|
+
- test/sample/text.rb
|