oj 3.3.9 → 3.3.10

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4f086bef3216ed10da36f2302af180253dfdd2db
4
- data.tar.gz: e1dfb9a7d1ec308b19ec532adb2dc320fcf6bf8b
3
+ metadata.gz: 687f7d149d0cf1490c71c850e9b899211bf93dff
4
+ data.tar.gz: e60c06c52ab2946307618cdc78a180ed2333f19b
5
5
  SHA512:
6
- metadata.gz: d3c5a71807363fcd682474d42760199bc8f4709505648c63aebbc9dadbc91677ae27f82c4712973d5fe01935998dcff46c611c92a920b39016d217a6c3cfd3a7
7
- data.tar.gz: fb39fbaae9c45f79ff49f30ab624838d3c7b2061d7aa6d891dc2c05e8f7cffd2dcd48bf08618264a12f6ad0092206de7a12b9c11773dae8f7fc0c38c8c27c22f
6
+ metadata.gz: '0287e158af4e2637f70aeaef9bd90fbdd92270ba8b94d58eb77f3371671ead837638440677a67f00880b1b0024098ea31530f843950c434154f72dfd844d8854'
7
+ data.tar.gz: 279a77556142e021b88e6e2b1b75ae93a11aa373dad3098f994559004ecfa4089ebd3514cd412b08004896438d014fde5a2c9dc27f87ad3558627920146870df
@@ -42,6 +42,8 @@ bigdecimal_dump(VALUE obj, int depth, Out out) {
42
42
  } else if (0 == strcasecmp("-Infinity", str)) {
43
43
  str = oj_nan_str(obj, out->opts->dump_opts.nan_dump, out->opts->mode, false, &len);
44
44
  oj_dump_raw(str, len, out);
45
+ } else if (No == out->opts->bigdec_as_num) {
46
+ oj_dump_cstr(str, len, 0, 0, out);
45
47
  } else {
46
48
  oj_dump_raw(str, len, out);
47
49
  }
@@ -830,7 +830,7 @@ oj_dump_cstr(const char *str, size_t cnt, bool is_sym, bool escape1, Out out) {
830
830
  if (JXEsc == out->opts->escape_mode && 0 < str - orig && 0 != (0x80 & *(str - 1))) {
831
831
  uint8_t c = (uint8_t)*(str - 1);
832
832
  int i;
833
- int scnt = str - orig;
833
+ int scnt = (int)(str - orig);
834
834
 
835
835
  // Last utf-8 characters must be 0x10xxxxxx. The start must be
836
836
  // 0x110xxxxx for 2 characters, 0x1110xxxx for 3, and 0x11110xxx for
@@ -42,7 +42,7 @@ dump_data(VALUE obj, int depth, Out out, bool as_ok) {
42
42
  const char *str = rb_string_value_ptr((VALUE*)&rstr);
43
43
  int len = (int)RSTRING_LEN(rstr);
44
44
 
45
- if (Yes == out->opts->bigdec_as_num) {
45
+ if (No != out->opts->bigdec_as_num) {
46
46
  oj_dump_raw(str, len, out);
47
47
  } else if (0 == strcasecmp("Infinity", str)) {
48
48
  str = oj_nan_str(obj, out->opts->dump_opts.nan_dump, out->opts->mode, true, &len);
@@ -341,7 +341,7 @@ hat_value(ParseInfo pi, Val parent, const char *key, size_t klen, volatile VALUE
341
341
  volatile VALUE sc;
342
342
  volatile VALUE e1;
343
343
  int slen;
344
-
344
+
345
345
  if (0 == len) {
346
346
  oj_set_error_at(pi, oj_parse_error_class, __FILE__, __LINE__, "Invalid struct data");
347
347
  return 1;
@@ -380,14 +380,14 @@ hat_value(ParseInfo pi, Val parent, const char *key, size_t klen, volatile VALUE
380
380
  } else {
381
381
  int i;
382
382
 
383
- for (i = 0; i < slen; i++) {
383
+ for (i = 0; i < len - 1; i++) {
384
384
  rb_struct_aset(parent->val, INT2FIX(i), RARRAY_PTR(value)[i + 1]);
385
385
  }
386
386
  }
387
387
  return 1;
388
388
  } else if (3 <= klen && '#' == key[1]) {
389
389
  volatile VALUE *a;
390
-
390
+
391
391
  if (2 != len) {
392
392
  oj_set_error_at(pi, oj_parse_error_class, __FILE__, __LINE__, "invalid hash pair");
393
393
  return 1;
@@ -602,7 +602,7 @@ hash_set_value(ParseInfo pi, Val kval, VALUE value) {
602
602
  if (3 <= klen && '^' == *key && '#' == key[1] && T_ARRAY == rb_type(value)) {
603
603
  long len = RARRAY_LEN(value);
604
604
  volatile VALUE *a = RARRAY_PTR(value);
605
-
605
+
606
606
  if (2 != len) {
607
607
  oj_set_error_at(pi, oj_parse_error_class, __FILE__, __LINE__, "invalid hash pair");
608
608
  return;
@@ -683,7 +683,7 @@ array_append_cstr(ParseInfo pi, const char *str, size_t len, const char *orig) {
683
683
  rb_ary_push(stack_peek(&pi->stack)->val, oj_circ_array_get(pi->circ_array, i));
684
684
  return;
685
685
  }
686
-
686
+
687
687
  }
688
688
  }
689
689
  rb_ary_push(stack_peek(&pi->stack)->val, str_to_value(pi, str, len, orig));
@@ -38,6 +38,7 @@ ID oj_array_end_id;
38
38
  ID oj_array_start_id;
39
39
  ID oj_as_json_id;
40
40
  ID oj_begin_id;
41
+ ID oj_bigdecimal_id;
41
42
  ID oj_end_id;
42
43
  ID oj_exclude_end_id;
43
44
  ID oj_error_id;
@@ -167,7 +168,7 @@ struct _Options oj_default_options = {
167
168
  ObjectMode, // mode
168
169
  Yes, // class_cache
169
170
  UnixTime, // time_format
170
- Yes, // bigdec_as_num
171
+ NotSet, // bigdec_as_num
171
172
  AutoDec, // bigdec_load
172
173
  No, // to_hash
173
174
  No, // to_json
@@ -545,13 +546,16 @@ oj_parse_options(VALUE ropts, Options copts) {
545
546
  }
546
547
  }
547
548
  for (o = ynos; 0 != o->attr; o++) {
548
- if (Qnil != (v = rb_hash_lookup(ropts, o->sym))) {
549
- if (Qtrue == v) {
549
+ if (Qtrue == rb_funcall(ropts, oj_has_key_id, 1, o->sym)) {
550
+ v = rb_hash_lookup(ropts, o->sym);
551
+ if (Qnil == v) {
552
+ *o->attr = NotSet;
553
+ } else if (Qtrue == v) {
550
554
  *o->attr = Yes;
551
555
  } else if (Qfalse == v) {
552
556
  *o->attr = No;
553
557
  } else {
554
- rb_raise(rb_eArgError, "%s must be true or false.", rb_id2name(SYM2ID(o->sym)));
558
+ rb_raise(rb_eArgError, "%s must be true, false, or nil.", rb_id2name(SYM2ID(o->sym)));
555
559
  }
556
560
  }
557
561
  }
@@ -1525,13 +1529,15 @@ Init_oj() {
1525
1529
  oj_array_end_id = rb_intern("array_end");
1526
1530
  oj_array_start_id = rb_intern("array_start");
1527
1531
  oj_as_json_id = rb_intern("as_json");
1528
- oj_error_id = rb_intern("error");
1529
1532
  oj_begin_id = rb_intern("begin");
1533
+ oj_bigdecimal_id = rb_intern("BigDecimal");
1530
1534
  oj_end_id = rb_intern("end");
1535
+ oj_error_id = rb_intern("error");
1531
1536
  oj_exclude_end_id = rb_intern("exclude_end?");
1532
1537
  oj_file_id = rb_intern("file?");
1533
1538
  oj_fileno_id = rb_intern("fileno");
1534
1539
  oj_ftype_id = rb_intern("ftype");
1540
+ oj_has_key_id = rb_intern("has_key?");
1535
1541
  oj_hash_end_id = rb_intern("hash_end");
1536
1542
  oj_hash_key_id = rb_intern("hash_key");
1537
1543
  oj_hash_set_id = rb_intern("hash_set");
@@ -1548,8 +1554,8 @@ Init_oj() {
1548
1554
  oj_replace_id = rb_intern("replace");
1549
1555
  oj_stat_id = rb_intern("stat");
1550
1556
  oj_string_id = rb_intern("string");
1551
- oj_to_hash_id = rb_intern("to_hash");
1552
1557
  oj_to_h_id = rb_intern("to_h");
1558
+ oj_to_hash_id = rb_intern("to_hash");
1553
1559
  oj_to_json_id = rb_intern("to_json");
1554
1560
  oj_to_s_id = rb_intern("to_s");
1555
1561
  oj_to_sym_id = rb_intern("to_sym");
@@ -1561,7 +1567,6 @@ Init_oj() {
1561
1567
  oj_utc_offset_id = rb_intern("utc_offset");
1562
1568
  oj_utcq_id = rb_intern("utc?");
1563
1569
  oj_write_id = rb_intern("write");
1564
- oj_has_key_id = rb_intern("has_key?");
1565
1570
 
1566
1571
  rb_require("oj/bag");
1567
1572
  rb_require("oj/error");
@@ -330,6 +330,7 @@ extern ID oj_array_end_id;
330
330
  extern ID oj_array_start_id;
331
331
  extern ID oj_as_json_id;
332
332
  extern ID oj_begin_id;
333
+ extern ID oj_bigdecimal_id;
333
334
  extern ID oj_end_id;
334
335
  extern ID oj_error_id;
335
336
  extern ID oj_exclude_end_id;
@@ -757,7 +757,7 @@ oj_num_as_value(NumInfo ni) {
757
757
  }
758
758
  } else { // decimal
759
759
  if (ni->big) {
760
- rnum = rb_funcall(oj_bigdecimal_class, oj_new_id, 1, rb_str_new(ni->str, ni->len));
760
+ rnum = rb_funcall(rb_cObject, oj_bigdecimal_id, 1, rb_str_new(ni->str, ni->len));
761
761
  if (ni->no_big) {
762
762
  rnum = rb_funcall(rnum, rb_intern("to_f"), 0);
763
763
  }
@@ -770,7 +770,7 @@ oj_num_as_value(NumInfo ni) {
770
770
  // 15 digits. This attempts to fix those few cases where this
771
771
  // occurs.
772
772
  if ((long double)INT64_MAX > d && (int64_t)d != (ni->i * ni->div + ni->num)) {
773
- rnum = rb_funcall(oj_bigdecimal_class, oj_new_id, 1, rb_str_new(ni->str, ni->len));
773
+ rnum = rb_funcall(rb_cObject, oj_bigdecimal_id, 1, rb_str_new(ni->str, ni->len));
774
774
  if (ni->no_big) {
775
775
  rnum = rb_funcall(rnum, rb_intern("to_f"), 0);
776
776
  }
@@ -212,6 +212,8 @@ dump_bigdecimal(VALUE obj, int depth, Out out, bool as_ok) {
212
212
 
213
213
  if ('I' == *str || 'N' == *str || ('-' == *str && 'I' == str[1])) {
214
214
  oj_dump_nil(Qnil, depth, out, false);
215
+ } else if (Yes == out->opts->bigdec_as_num) {
216
+ oj_dump_raw(str, RSTRING_LEN(rstr), out);
215
217
  } else {
216
218
  oj_dump_cstr(str, RSTRING_LEN(rstr), 0, 0, out);
217
219
  }
@@ -475,17 +477,65 @@ encoder_new(int argc, VALUE *argv, VALUE self) {
475
477
  return Data_Wrap_Struct(encoder_class, encoder_mark, encoder_free, e);
476
478
  }
477
479
 
480
+ static VALUE
481
+ resolve_classpath(const char *name) {
482
+ char class_name[1024];
483
+ VALUE clas;
484
+ char *end = class_name + sizeof(class_name) - 1;
485
+ char *s;
486
+ const char *n = name;
487
+ ID cid;
488
+
489
+ clas = rb_cObject;
490
+ for (s = class_name; '\0' != *n; n++) {
491
+ if (':' == *n) {
492
+ *s = '\0';
493
+ n++;
494
+ if (':' != *n) {
495
+ return Qnil;
496
+ }
497
+ cid = rb_intern(class_name);
498
+ if (!rb_const_defined_at(clas, cid)) {
499
+ return Qnil;
500
+ }
501
+ clas = rb_const_get_at(clas, cid);
502
+ s = class_name;
503
+ } else if (end <= s) {
504
+ return Qnil;
505
+ } else {
506
+ *s++ = *n;
507
+ }
508
+ }
509
+ *s = '\0';
510
+ cid = rb_intern(class_name);
511
+ if (!rb_const_defined_at(clas, cid)) {
512
+ return Qnil;
513
+ }
514
+ clas = rb_const_get_at(clas, cid);
515
+
516
+ return clas;
517
+ }
518
+
478
519
  static void
479
520
  optimize(int argc, VALUE *argv, ROptTable rot, bool on) {
480
521
  ROpt ro;
481
-
522
+
482
523
  if (0 == argc) {
483
- int i;
524
+ int i;
525
+ NamedFunc nf;
526
+ VALUE clas;
484
527
 
485
528
  oj_rails_hash_opt = on;
486
529
  oj_rails_array_opt = on;
487
530
  oj_rails_float_opt = on;
488
531
 
532
+ for (nf = dump_map; NULL != nf->name; nf++) {
533
+ if (Qnil != (clas = resolve_classpath(nf->name))) {
534
+ if (NULL == oj_rails_get_opt(rot, clas)) {
535
+ create_opt(rot, clas);
536
+ }
537
+ }
538
+ }
489
539
  for (i = 0; i < rot->len; i++) {
490
540
  rot->table[i].on = on;
491
541
  }
@@ -381,7 +381,7 @@ read_num(ParseInfo pi, const char *key) {
381
381
 
382
382
  *pi->s = '\0';
383
383
  if (pi->has_add_value) {
384
- call_add_value(pi->handler, rb_funcall(oj_bigdecimal_class, oj_new_id, 1, rb_str_new2(start)), key);
384
+ call_add_value(pi->handler, rb_funcall(rb_cObject, oj_bigdecimal_id, 1, rb_str_new2(start)), key);
385
385
  }
386
386
  *pi->s = c;
387
387
  } else {
@@ -399,7 +399,7 @@ read_num(ParseInfo pi, const char *key) {
399
399
 
400
400
  *pi->s = '\0';
401
401
  if (pi->has_add_value) {
402
- call_add_value(pi->handler, rb_funcall(oj_bigdecimal_class, oj_new_id, 1, rb_str_new2(start)), key);
402
+ call_add_value(pi->handler, rb_funcall(rb_cObject, oj_bigdecimal_id, 1, rb_str_new2(start)), key);
403
403
  }
404
404
  *pi->s = c;
405
405
  } else {
@@ -1,5 +1,5 @@
1
1
 
2
2
  module Oj
3
3
  # Current version of the module.
4
- VERSION = '3.3.9'
4
+ VERSION = '3.3.10'
5
5
  end
@@ -94,7 +94,7 @@ information.
94
94
  | :array_nl | String | | | | | | x | |
95
95
  | :ascii_only | Boolean | x | x | 2 | 2 | x | x | |
96
96
  | :auto_define | Boolean | | | | | x | x | |
97
- | :bigdecimal_as_decimal | Boolean | | | | | x | x | |
97
+ | :bigdecimal_as_decimal | Boolean | | | | 3 | x | x | |
98
98
  | :bigdecimal_load | Boolean | | | | | | x | |
99
99
  | :circular | Boolean | x | x | x | x | x | x | |
100
100
  | :class_cache | Boolean | | | | | x | x | |
@@ -104,17 +104,17 @@ information.
104
104
  | :escape_mode | Symbol | | | | | | x | |
105
105
  | :float_precision | Fixnum | x | x | | | | x | |
106
106
  | :hash_class | Class | | | x | x | | x | |
107
- | :indent | Integer | x | x | 3 | 3 | x | x | x |
107
+ | :indent | Integer | x | x | 3 | 4 | x | x | x |
108
108
  | :indent_str | String | | | x | x | | x | |
109
109
  | :match_string | Hash | | | x | x | | x | |
110
- | :max_nesting | Fixnum | 4 | 4 | x | | 4 | 4 | |
110
+ | :max_nesting | Fixnum | 4 | 4 | x | | 5 | 4 | |
111
111
  | :mode | Symbol | - | - | - | - | - | - | |
112
112
  | :nan | Symbol | | | | | | x | |
113
113
  | :nilnil | Boolean | | | | | | x | |
114
114
  | :object_class | Class | | | x | | | x | |
115
115
  | :object_nl | String | | | x | x | | x | |
116
116
  | :omit_nil | Boolean | x | x | x | x | x | x | |
117
- | :quirks_mode | Boolean | | | 5 | | | x | |
117
+ | :quirks_mode | Boolean | | | 6 | | | x | |
118
118
  | :second_precision | Fixnum | | | | | x | x | |
119
119
  | :space | String | | | x | x | | x | |
120
120
  | :space_before | String | | | x | x | | x | |
@@ -129,19 +129,23 @@ information.
129
129
 
130
130
  2. The :ascii_only options is an undocumented json gem option.
131
131
 
132
- 3. The integer indent value in the default options will be honored by since
132
+ 3. By default the bigdecimal_as decimal is not set and the default encoding
133
+ for Rails is as a string. Setting the value to true will encode a
134
+ BigDecimal as a number which breaks compatibility.
135
+
136
+ 4. The integer indent value in the default options will be honored by since
133
137
  the json gem expects a String type the indent in calls to 'to_json()',
134
138
  'Oj.generate()', or 'Oj.generate_fast()' expect a String and not an
135
139
  integer.
136
140
 
137
- 4. The max_nesting option is for the json gem and rails only. It exists for
141
+ 5. The max_nesting option is for the json gem and rails only. It exists for
138
142
  compatibility. For other Oj dump modes the maximum nesting is set to over
139
143
  1000. If reference loops exist in the object being dumped then using the
140
144
  `:circular` option is a far better choice. It adds a slight overhead but
141
145
  detects an object that appears more than once in a dump and does not dump
142
146
  that object a second time.
143
147
 
144
- 5. The quirks mode option is no longer supported in the most recent json
148
+ 6. The quirks mode option is no longer supported in the most recent json
145
149
  gem. It is supported by Oj for backward compatibility with older json gem
146
150
  versions.
147
151
 
@@ -5,20 +5,21 @@
5
5
  $LOAD_PATH.unshift File.expand_path("../../#{dir}", __FILE__)
6
6
  end
7
7
 
8
+ require 'rails'
9
+ require 'active_support'
10
+ require 'active_support/json'
8
11
  require 'oj'
9
12
 
10
- S = Struct.new(
11
- :chunk_seq,
12
- :youngest,
13
- :oldest,
14
- :size
15
- )
16
-
17
- data = S.new(
18
- chunk_seq: 666000,
19
- youngest: nil,
20
- oldest: nil,
21
- size: 1
22
- )
23
-
24
- puts Oj.dump(data, mode: :object)
13
+ x = {"a": BigDecimal("1.1"), "t": Time.now}
14
+
15
+ #ActiveSupport.encode_big_decimal_as_string = false
16
+
17
+ Oj.optimize_rails
18
+
19
+ puts "to_json #{x.to_json}"
20
+
21
+ Oj.default_options = { bigdecimal_as_decimal: true}
22
+ #puts Oj.default_options
23
+
24
+ puts "to_json #{x.to_json}"
25
+
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
- # encoding: UTF-8
2
+ # encoding: utf-8
3
3
 
4
4
  $: << File.dirname(__FILE__)
5
5
  $oj_dir = File.dirname(File.expand_path(File.dirname(__FILE__)))
@@ -274,13 +274,9 @@ class CompatJuice < Minitest::Test
274
274
  def test_bigdecimal
275
275
  # BigDecimals are dumped as strings and can not be restored to the
276
276
  # original value.
277
- json = Oj.dump(BigDecimal.new('3.14159265358979323846'))
278
- if RUBY_VERSION >= '2.4.0'
279
- # 2.4.0 changes the exponent to lowercase
280
- assert_equal('"0.314159265358979323846e1"', json)
281
- else
282
- assert_equal('"0.314159265358979323846E1"', json)
283
- end
277
+ json = Oj.dump(BigDecimal('3.14159265358979323846'))
278
+ # 2.4.0 changes the exponent to lowercase
279
+ assert_equal('"0.314159265358979323846e1"', json.downcase)
284
280
  end
285
281
 
286
282
  def test_infinity
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
- # encoding: UTF-8
2
+ # encoding: utf-8
3
3
 
4
4
  $: << File.dirname(__FILE__)
5
5
  $oj_dir = File.dirname(File.expand_path(File.dirname(__FILE__)))
@@ -203,12 +203,9 @@ class CustomJuice < Minitest::Test
203
203
  end
204
204
 
205
205
  def test_bigdecimal
206
- if '2.4.0' <= RUBY_VERSION
207
- assert_equal('0.314159265358979323846e1', Oj.dump(BigDecimal.new('3.14159265358979323846'), :bigdecimal_load => true))
208
- else
209
- assert_equal('0.314159265358979323846E1', Oj.dump(BigDecimal.new('3.14159265358979323846'), :bigdecimal_load => true))
210
- end
211
- dump_and_load(BigDecimal.new('3.14159265358979323846'), false, :bigdecimal_load => true)
206
+ assert_equal('0.314159265358979323846e1', Oj.dump(BigDecimal('3.14159265358979323846'), bigdecimal_as_decimal: true).downcase())
207
+ assert_equal('"0.314159265358979323846e1"', Oj.dump(BigDecimal('3.14159265358979323846'), bigdecimal_as_decimal: false).downcase())
208
+ dump_and_load(BigDecimal('3.14159265358979323846'), false, :bigdecimal_load => true)
212
209
  end
213
210
 
214
211
  def test_object
@@ -184,20 +184,20 @@ class FileJuice < Minitest::Test
184
184
  def test_bigdecimal_strict
185
185
  mode = Oj.default_options[:mode]
186
186
  Oj.default_options = {:mode => :strict}
187
- dump_and_load(BigDecimal.new('3.14159265358979323846'), false)
187
+ dump_and_load(BigDecimal('3.14159265358979323846'), false)
188
188
  Oj.default_options = {:mode => mode}
189
189
  end
190
190
 
191
191
  def test_bigdecimal_null
192
192
  mode = Oj.default_options[:mode]
193
193
  Oj.default_options = {:mode => :null}
194
- dump_and_load(BigDecimal.new('3.14159265358979323846'), false)
194
+ dump_and_load(BigDecimal('3.14159265358979323846'), false)
195
195
  Oj.default_options = {:mode => mode}
196
196
  end
197
197
 
198
198
  def test_bigdecimal_object
199
199
  Oj.default_options = {:mode => :object}
200
- dump_and_load(BigDecimal.new('3.14159265358979323846'), false)
200
+ dump_and_load(BigDecimal('3.14159265358979323846'), false)
201
201
  end
202
202
 
203
203
  # Date
@@ -208,11 +208,11 @@ class NullJuice < Minitest::Test
208
208
  # BigDecimal
209
209
  def test_bigdecimal_strict
210
210
  Oj.default_options = { :bigdecimal_load => true}
211
- dump_and_load(BigDecimal.new('3.14159265358979323846'), false)
211
+ dump_and_load(BigDecimal('3.14159265358979323846'), false)
212
212
  end
213
213
 
214
214
  def test_bigdecimal_load
215
- orig = BigDecimal.new('80.51')
215
+ orig = BigDecimal('80.51')
216
216
  json = Oj.dump(orig, :mode => :strict, :bigdecimal_as_decimal => true)
217
217
  bg = Oj.load(json, :mode => :strict, :bigdecimal_load => true)
218
218
  assert_equal(BigDecimal, bg.class)
@@ -345,19 +345,19 @@ class ObjectJuice < Minitest::Test
345
345
 
346
346
  # BigDecimal
347
347
  def test_bigdecimal_object
348
- dump_and_load(BigDecimal.new('3.14159265358979323846'), false)
348
+ dump_and_load(BigDecimal('3.14159265358979323846'), false)
349
349
  end
350
350
 
351
351
  def test_bigdecimal_load
352
- orig = BigDecimal.new('80.51')
352
+ orig = BigDecimal('80.51')
353
353
  json = Oj.dump(orig, :mode => :object, :bigdecimal_as_decimal => true)
354
354
  bg = Oj.load(json, :mode => :object, :bigdecimal_load => true)
355
355
  assert_equal(BigDecimal, bg.class)
356
356
  assert_equal(orig, bg)
357
357
  # Infinity is the same for Float and BigDecimal
358
- json = Oj.dump(BigDecimal.new('Infinity'), :mode => :object)
358
+ json = Oj.dump(BigDecimal('Infinity'), :mode => :object)
359
359
  assert_equal('Infinity', json)
360
- json = Oj.dump(BigDecimal.new('-Infinity'), :mode => :object)
360
+ json = Oj.dump(BigDecimal('-Infinity'), :mode => :object)
361
361
  assert_equal('-Infinity', json)
362
362
  end
363
363
 
@@ -805,6 +805,14 @@ class ObjectJuice < Minitest::Test
805
805
  assert_equal(h2['b'].__id__, h2.__id__)
806
806
  end
807
807
 
808
+
809
+ def test_json_object_missing_fields
810
+ json = %{{ "^u": [ "ObjectJuice::Stuck",1]}}
811
+
812
+ obj = Oj.load(json, mode: :object)
813
+ assert_nil(obj['b'])
814
+ end
815
+
808
816
  def test_circular_array
809
817
  a = [7]
810
818
  a << a
@@ -895,11 +903,11 @@ class ObjectJuice < Minitest::Test
895
903
  json = Oj.dump(jam, :omit_nil => true, :mode => :object)
896
904
  assert_equal(%|{"^o":"ObjectJuice::Jam","x":{"a":1}}|, json)
897
905
  end
898
-
906
+
899
907
  def test_odd_date
900
908
  dump_and_load(Date.new(2012, 6, 19), false)
901
909
  end
902
-
910
+
903
911
  def test_odd_datetime
904
912
  dump_and_load(DateTime.new(2012, 6, 19, 13, 5, Rational(4, 3)), false)
905
913
  dump_and_load(DateTime.new(2012, 6, 19, 13, 5, Rational(7123456789, 1000000000)), false)
@@ -217,11 +217,11 @@ class StrictJuice < Minitest::Test
217
217
  # BigDecimal
218
218
  def test_bigdecimal_strict
219
219
  Oj.default_options = { :bigdecimal_load => true}
220
- dump_and_load(BigDecimal.new('3.14159265358979323846'), false)
220
+ dump_and_load(BigDecimal('3.14159265358979323846'), false)
221
221
  end
222
222
 
223
223
  def test_bigdecimal_load
224
- orig = BigDecimal.new('80.51')
224
+ orig = BigDecimal('80.51')
225
225
  json = Oj.dump(orig, :mode => :strict, :bigdecimal_as_decimal => true)
226
226
  bg = Oj.load(json, :mode => :strict, :bigdecimal_load => true)
227
227
  assert_equal(BigDecimal, bg.class)
@@ -486,13 +486,13 @@ class Juice < Minitest::Test
486
486
  def test_bigdecimal_null
487
487
  mode = Oj.default_options[:mode]
488
488
  Oj.default_options = {:mode => :null}
489
- dump_and_load(BigDecimal.new('3.14159265358979323846'), false)
489
+ dump_and_load(BigDecimal('3.14159265358979323846'), false)
490
490
  Oj.default_options = {:mode => mode}
491
491
  end
492
492
 
493
493
  def test_infinity
494
494
  n = Oj.load('Infinity', :mode => :object)
495
- assert_equal(BigDecimal.new('Infinity').to_f, n);
495
+ assert_equal(BigDecimal('Infinity').to_f, n);
496
496
  x = Oj.load('Infinity', :mode => :compat)
497
497
  assert_equal('Infinity', x.to_s)
498
498
  end
@@ -157,11 +157,11 @@ class WabJuice < Minitest::Test
157
157
 
158
158
  # BigDecimal
159
159
  def test_bigdecimal_wab
160
- dump_and_load(BigDecimal.new('3.14159265358979323846'), false)
160
+ dump_and_load(BigDecimal('3.14159265358979323846'), false)
161
161
  end
162
162
 
163
163
  def test_bigdecimal_load
164
- orig = BigDecimal.new('80.51')
164
+ orig = BigDecimal('80.51')
165
165
  json = Oj.dump(orig, mode: :wab)
166
166
  bg = Oj.load(json, :mode => :wab, :bigdecimal_load => true)
167
167
  assert_equal(BigDecimal, bg.class)
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.3.9
4
+ version: 3.3.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Ohler
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-10-27 00:00:00.000000000 Z
11
+ date: 2017-12-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake-compiler