oj 2.2.2 → 2.2.3

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of oj might be problematic. Click here for more details.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 01dd99731dba1d9feeffe3135e41b282718c6342
4
- data.tar.gz: 0c635bcad7be8c0a8b86a074dc2cc42946a4938a
3
+ metadata.gz: bf666d35187060e360daf53c2d0bedd178d3c686
4
+ data.tar.gz: 3e855525649cf4cec80eaa2e49b1d895f2db9eee
5
5
  SHA512:
6
- metadata.gz: 9cabf96957642d870530a33ed6b4236505d6e67e06d6cddbb7f2b29e2dcc567a12b844a5fe7abe317bb0f3a65cccadf81240c8af23aa4ff7c45363c744bfc045
7
- data.tar.gz: 2e2b979fbe2a517b04bca9eb3144b9c3edfeccfd33a3849b4d175a882036b3dff2631de3c888fa608fdbc13a1f3e3b97cbd71fef3f5b87d3ac27074d70606109
6
+ metadata.gz: 7b6c183e662e435f8eaf00079f8caa2e306d20f8fbfafcd30b7d86e8e5f715d8fe3ebf6ceaadc4e217ce140df7b572807cb5a980af22836b76a8cd971a540440
7
+ data.tar.gz: fa4fe7655132ab085ce93ca6604dcfba71cfa925480c279db93dc2baf2ede9fe5d8592c101af7045587656d6e418d2ee7e7049ef49ef681a066e95a80ed9f372
data/README.md CHANGED
@@ -20,6 +20,12 @@ Follow [@peterohler on Twitter](http://twitter.com/#!/peterohler) for announceme
20
20
 
21
21
  [![Build Status](https://secure.travis-ci.org/ohler55/oj.png?branch=master)](http://travis-ci.org/ohler55/oj)
22
22
 
23
+ ### Current Release 2.2.3
24
+
25
+ - Fixed struct segfault on load.
26
+
27
+ - Added option to force float on load if a decimal number.
28
+
23
29
  ### Current Release 2.2.2
24
30
 
25
31
  - Added mutex support for Windows.
@@ -181,50 +181,35 @@ hat_num(ParseInfo pi, Val parent, const char *key, size_t klen, NumInfo ni) {
181
181
 
182
182
  static int
183
183
  hat_value(ParseInfo pi, Val parent, const char *key, size_t klen, volatile VALUE value) {
184
- if (2 == klen && 'u' == key[1] && T_ARRAY == rb_type(value)) {
185
- #if HAS_RSTRUCT
186
- long len = RARRAY_LEN(value);
187
- volatile VALUE *a = RARRAY_PTR(value);
188
- volatile VALUE sc;
189
- volatile VALUE s;
190
- volatile VALUE *sv;
191
-
192
- if (0 == len) {
193
- oj_set_error_at(pi, oj_parse_error_class, __FILE__, __LINE__, "Invalid struct data");
194
- return 1;
195
- }
196
- sc = rb_const_get(oj_struct_class, rb_to_id(*a));
197
- //sc = rb_const_get(oj_struct_class, rb_intern_str(*a));
198
- // use encoding as the indicator for Ruby 1.8.7 or 1.9.x
199
- #if HAS_ENCODING_SUPPORT
200
- s = rb_struct_alloc_noinit(sc);
201
- #else
202
- s = rb_struct_new(sc, Qnil, Qnil, Qnil, Qnil, Qnil, Qnil, Qnil, Qnil, Qnil, Qnil, Qnil, Qnil, Qnil, Qnil, Qnil, Qnil, Qnil, Qnil, Qnil, Qnil);
203
- #endif
204
- sv = RSTRUCT_PTR(s);
205
- if (RSTRUCT_LEN(s) < len - 1) {
206
- oj_set_error_at(pi, oj_parse_error_class, __FILE__, __LINE__, "Too many elements for Struct");
184
+ if (T_ARRAY == rb_type(value)) {
185
+ int len = (int)RARRAY_LEN(value);
186
+
187
+ if (2 == klen && 'u' == key[1]) {
188
+ volatile VALUE sc;
189
+
190
+ if (0 == len) {
191
+ oj_set_error_at(pi, oj_parse_error_class, __FILE__, __LINE__, "Invalid struct data");
192
+ return 1;
193
+ }
194
+ // If struct is not defined of new is not supported on the class then
195
+ // let this fail and raise an exception.
196
+ sc = rb_const_get(oj_struct_class, rb_to_id(*RARRAY_PTR(value)));
197
+ parent->val = rb_funcall2(sc, oj_new_id, len - 1, RARRAY_PTR(value) + 1);
198
+
207
199
  return 1;
208
- }
209
- for (a++; 0 < len; len--, a++, sv++) {
210
- *sv = *a;
211
- }
212
- parent->val = s;
213
- #else
214
- oj_set_error_at(pi, oj_parse_error_class, __FILE__, __LINE__, "Ruby structs not supported with this version of Ruby");
215
- #endif
216
- return 1;
217
- } else if (3 <= klen && '#' == key[1] && T_ARRAY == rb_type(value)) {
218
- long len = RARRAY_LEN(value);
219
- volatile VALUE *a = RARRAY_PTR(value);
200
+ } else if (3 <= klen && '#' == key[1]) {
201
+ volatile VALUE *a;
220
202
 
221
- if (2 != len) {
222
- oj_set_error_at(pi, oj_parse_error_class, __FILE__, __LINE__, "invalid hash pair");
203
+ if (2 != len) {
204
+ oj_set_error_at(pi, oj_parse_error_class, __FILE__, __LINE__, "invalid hash pair");
205
+ return 1;
206
+ }
207
+ parent->val = rb_hash_new();
208
+ a = RARRAY_PTR(value);
209
+ rb_hash_aset(parent->val, *a, a[1]);
210
+
223
211
  return 1;
224
212
  }
225
- parent->val = rb_hash_new();
226
- rb_hash_aset(parent->val, *a, a[1]);
227
- return 1;
228
213
  }
229
214
  return 0;
230
215
  }
@@ -90,22 +90,24 @@ VALUE oj_time_class;
90
90
 
91
91
  VALUE oj_slash_string;
92
92
 
93
- static VALUE ascii_sym;
94
93
  static VALUE ascii_only_sym;
94
+ static VALUE ascii_sym;
95
95
  static VALUE auto_define_sym;
96
+ static VALUE auto_sym;
96
97
  static VALUE bigdecimal_as_decimal_sym;
97
98
  static VALUE bigdecimal_load_sym;
99
+ static VALUE bigdecimal_sym;
98
100
  static VALUE circular_sym;
99
101
  static VALUE class_cache_sym;
100
102
  static VALUE compat_sym;
101
103
  static VALUE create_id_sym;
102
104
  static VALUE escape_mode_sym;
105
+ static VALUE float_sym;
103
106
  static VALUE indent_sym;
104
107
  static VALUE json_sym;
105
108
  static VALUE mode_sym;
106
109
  static VALUE null_sym;
107
110
  static VALUE object_sym;
108
- static VALUE xss_safe_sym;
109
111
  static VALUE ruby_sym;
110
112
  static VALUE sec_prec_sym;
111
113
  static VALUE strict_sym;
@@ -113,6 +115,7 @@ static VALUE symbol_keys_sym;
113
115
  static VALUE time_format_sym;
114
116
  static VALUE unix_sym;
115
117
  static VALUE xmlschema_sym;
118
+ static VALUE xss_safe_sym;
116
119
 
117
120
  static VALUE array_nl_sym;
118
121
  static VALUE create_additions_sym;
@@ -146,7 +149,7 @@ struct _Options oj_default_options = {
146
149
  Yes, // class_cache
147
150
  UnixTime, // time_format
148
151
  Yes, // bigdec_as_num
149
- No, // bigdec_load
152
+ AutoDec, // bigdec_load
150
153
  json_class, // create_id
151
154
  10, // create_id_len
152
155
  9, // sec_prec
@@ -167,7 +170,7 @@ static VALUE define_mimic_json(int argc, VALUE *argv, VALUE self);
167
170
  * - mode: [:object|:strict|:compat|:null] load and dump modes to use for JSON
168
171
  * - time_format: [:unix|:xmlschema|:ruby] time format when dumping in :compat mode
169
172
  * - bigdecimal_as_decimal: [true|false|nil] dump BigDecimal as a decimal number or as a String
170
- * - bigdecimal_load: [true|false|nil] load decimals as BigDecimal instead of as a Float
173
+ * - bigdecimal_load: [:bigdecimal|:float|:auto] load decimals as BigDecimal instead of as a Float. :auto pick the most precise for the number of digits.
171
174
  * - create_id: [String|nil] create id for json compatible object encoding, default is 'json_create'
172
175
  * - second_precision: [Fixnum|nil] number of digits after the decimal when dumping the seconds portion of time
173
176
  * @return [Hash] all current option settings.
@@ -183,7 +186,6 @@ get_def_opts(VALUE self) {
183
186
  rb_hash_aset(opts, auto_define_sym, (Yes == oj_default_options.auto_define) ? Qtrue : ((No == oj_default_options.auto_define) ? Qfalse : Qnil));
184
187
  rb_hash_aset(opts, symbol_keys_sym, (Yes == oj_default_options.sym_key) ? Qtrue : ((No == oj_default_options.sym_key) ? Qfalse : Qnil));
185
188
  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));
186
- rb_hash_aset(opts, bigdecimal_load_sym, (Yes == oj_default_options.bigdec_load) ? Qtrue : ((No == oj_default_options.bigdec_load) ? Qfalse : Qnil));
187
189
  switch (oj_default_options.mode) {
188
190
  case StrictMode: rb_hash_aset(opts, mode_sym, strict_sym); break;
189
191
  case CompatMode: rb_hash_aset(opts, mode_sym, compat_sym); break;
@@ -203,6 +205,12 @@ get_def_opts(VALUE self) {
203
205
  case UnixTime:
204
206
  default: rb_hash_aset(opts, time_format_sym, unix_sym); break;
205
207
  }
208
+ switch (oj_default_options.bigdec_load) {
209
+ case BigDec: rb_hash_aset(opts, bigdecimal_load_sym, bigdecimal_sym); break;
210
+ case FloatDec: rb_hash_aset(opts, bigdecimal_load_sym, float_sym); break;
211
+ case AutoDec:
212
+ default: rb_hash_aset(opts, bigdecimal_load_sym, auto_sym); break;
213
+ }
206
214
  rb_hash_aset(opts, create_id_sym, (0 == oj_default_options.create_id) ? Qnil : rb_str_new2(oj_default_options.create_id));
207
215
 
208
216
  return opts;
@@ -221,7 +229,7 @@ get_def_opts(VALUE self) {
221
229
  * escaped sequences if :ascii, :json is standand UTF-8 JSON encoding,
222
230
  * and :xss_safe escapes &, <, and >, and some others.
223
231
  * @param [true|false|nil] :bigdecimal_as_decimal dump BigDecimal as a decimal number or as a String
224
- * @param [true|false|nil] :bigdecimal_load load decimals as a BigDecimal instead of as a Float
232
+ * @param [:bigdecimal|:float|:auto|nil] :bigdecimal_load load decimals as BigDecimal instead of as a Float. :auto pick the most precise for the number of digits.
225
233
  * @param [:object|:strict|:compat|:null] load and dump mode to use for JSON
226
234
  * :strict raises an exception when a non-supported Object is
227
235
  * encountered. :compat attempts to extract variable values from an
@@ -246,7 +254,6 @@ set_def_opts(VALUE self, VALUE opts) {
246
254
  { symbol_keys_sym, &oj_default_options.sym_key },
247
255
  { class_cache_sym, &oj_default_options.class_cache },
248
256
  { bigdecimal_as_decimal_sym, &oj_default_options.bigdec_as_num },
249
- { bigdecimal_load_sym, &oj_default_options.bigdec_load },
250
257
  { Qnil, 0 }
251
258
  };
252
259
  YesNoOpt o;
@@ -313,6 +320,19 @@ set_def_opts(VALUE self, VALUE opts) {
313
320
  rb_raise(rb_eArgError, ":encoding must be :json, :rails, or :ascii.");
314
321
  }
315
322
 
323
+ v = rb_hash_lookup(opts, bigdecimal_load_sym);
324
+ if (Qnil == v) {
325
+ // ignore
326
+ } else if (bigdecimal_sym == v || Qtrue == v) {
327
+ oj_default_options.bigdec_load = BigDec;
328
+ } else if (float_sym == v) {
329
+ oj_default_options.bigdec_load = FloatDec;
330
+ } else if (auto_sym == v || Qfalse == v) {
331
+ oj_default_options.bigdec_load = AutoDec;
332
+ } else {
333
+ rb_raise(rb_eArgError, ":bigdecimal_load must be :bigdecimal, :float, or :auto.");
334
+ }
335
+
316
336
  if (Qtrue == rb_funcall(opts, rb_intern("has_key?"), 1, create_id_sym)) {
317
337
  if (0 != oj_default_options.create_id) {
318
338
  if (json_class != oj_default_options.create_id) {
@@ -363,7 +383,6 @@ oj_parse_options(VALUE ropts, Options copts) {
363
383
  { symbol_keys_sym, &copts->sym_key },
364
384
  { class_cache_sym, &copts->class_cache },
365
385
  { bigdecimal_as_decimal_sym, &copts->bigdec_as_num },
366
- { bigdecimal_load_sym, &copts->bigdec_load },
367
386
  { Qnil, 0 }
368
387
  };
369
388
  YesNoOpt o;
@@ -428,6 +447,18 @@ oj_parse_options(VALUE ropts, Options copts) {
428
447
  }
429
448
  }
430
449
 
450
+ if (Qnil != (v = rb_hash_lookup(ropts, bigdecimal_load_sym))) {
451
+ if (bigdecimal_sym == v || Qtrue == v) {
452
+ copts->bigdec_load = BigDec;
453
+ } else if (float_sym == v) {
454
+ copts->bigdec_load = FloatDec;
455
+ } else if (auto_sym == v || Qfalse == v) {
456
+ copts->bigdec_load = AutoDec;
457
+ } else {
458
+ rb_raise(rb_eArgError, ":bigdecimal_load must be :bigdecimal, :float, or :auto.");
459
+ }
460
+ }
461
+
431
462
  if (Qtrue == rb_funcall(ropts, rb_intern("has_key?"), 1, create_id_sym)) {
432
463
  v = rb_hash_lookup(ropts, create_id_sym);
433
464
  if (Qnil == v) {
@@ -1240,22 +1271,24 @@ void Init_oj() {
1240
1271
  oj_struct_class = rb_const_get(rb_cObject, rb_intern("Struct"));
1241
1272
  oj_time_class = rb_const_get(rb_cObject, rb_intern("Time"));
1242
1273
 
1243
- ascii_sym = ID2SYM(rb_intern("ascii")); rb_gc_register_address(&ascii_sym);
1244
1274
  ascii_only_sym = ID2SYM(rb_intern("ascii_only")); rb_gc_register_address(&ascii_only_sym);
1275
+ ascii_sym = ID2SYM(rb_intern("ascii")); rb_gc_register_address(&ascii_sym);
1245
1276
  auto_define_sym = ID2SYM(rb_intern("auto_define")); rb_gc_register_address(&auto_define_sym);
1277
+ auto_sym = ID2SYM(rb_intern("auto")); rb_gc_register_address(&auto_sym);
1246
1278
  bigdecimal_as_decimal_sym = ID2SYM(rb_intern("bigdecimal_as_decimal"));rb_gc_register_address(&bigdecimal_as_decimal_sym);
1247
1279
  bigdecimal_load_sym = ID2SYM(rb_intern("bigdecimal_load"));rb_gc_register_address(&bigdecimal_load_sym);
1280
+ bigdecimal_sym = ID2SYM(rb_intern("bigdecimal")); rb_gc_register_address(&bigdecimal_sym);
1248
1281
  circular_sym = ID2SYM(rb_intern("circular")); rb_gc_register_address(&circular_sym);
1249
1282
  class_cache_sym = ID2SYM(rb_intern("class_cache")); rb_gc_register_address(&class_cache_sym);
1250
1283
  compat_sym = ID2SYM(rb_intern("compat")); rb_gc_register_address(&compat_sym);
1251
1284
  create_id_sym = ID2SYM(rb_intern("create_id")); rb_gc_register_address(&create_id_sym);
1252
1285
  escape_mode_sym = ID2SYM(rb_intern("escape_mode")); rb_gc_register_address(&escape_mode_sym);
1286
+ float_sym = ID2SYM(rb_intern("float")); rb_gc_register_address(&float_sym);
1253
1287
  indent_sym = ID2SYM(rb_intern("indent")); rb_gc_register_address(&indent_sym);
1254
1288
  json_sym = ID2SYM(rb_intern("json")); rb_gc_register_address(&json_sym);
1255
1289
  mode_sym = ID2SYM(rb_intern("mode")); rb_gc_register_address(&mode_sym);
1256
1290
  null_sym = ID2SYM(rb_intern("null")); rb_gc_register_address(&null_sym);
1257
1291
  object_sym = ID2SYM(rb_intern("object")); rb_gc_register_address(&object_sym);
1258
- xss_safe_sym = ID2SYM(rb_intern("xss_safe")); rb_gc_register_address(&xss_safe_sym);
1259
1292
  ruby_sym = ID2SYM(rb_intern("ruby")); rb_gc_register_address(&ruby_sym);
1260
1293
  sec_prec_sym = ID2SYM(rb_intern("second_precision"));rb_gc_register_address(&sec_prec_sym);
1261
1294
  strict_sym = ID2SYM(rb_intern("strict")); rb_gc_register_address(&strict_sym);
@@ -1263,6 +1296,7 @@ void Init_oj() {
1263
1296
  time_format_sym = ID2SYM(rb_intern("time_format")); rb_gc_register_address(&time_format_sym);
1264
1297
  unix_sym = ID2SYM(rb_intern("unix")); rb_gc_register_address(&unix_sym);
1265
1298
  xmlschema_sym = ID2SYM(rb_intern("xmlschema")); rb_gc_register_address(&xmlschema_sym);
1299
+ xss_safe_sym = ID2SYM(rb_intern("xss_safe")); rb_gc_register_address(&xss_safe_sym);
1266
1300
 
1267
1301
  oj_slash_string = rb_str_new2("/"); rb_gc_register_address(&oj_slash_string);
1268
1302
 
@@ -92,6 +92,12 @@ typedef enum {
92
92
  ASCIIEsc = 'a'
93
93
  } Encoding;
94
94
 
95
+ typedef enum {
96
+ BigDec = 'b',
97
+ FloatDec = 'f',
98
+ AutoDec = 'a'
99
+ } BigLoad;
100
+
95
101
  typedef struct _DumpOpts {
96
102
  const char *indent;
97
103
  const char *before_sep;
@@ -115,7 +121,7 @@ typedef struct _Options {
115
121
  char class_cache; // YesNo
116
122
  char time_format; // TimeFormat
117
123
  char bigdec_as_num; // YesNo
118
- char bigdec_load; // YesNo
124
+ char bigdec_load; // BigLoad
119
125
  const char *create_id; // 0 or string
120
126
  size_t create_id_len; // length of create_id
121
127
  int sec_prec; // second precision when dumping time
@@ -389,6 +389,7 @@ read_num(ParseInfo pi) {
389
389
  ni.infinity = 0;
390
390
  ni.nan = 0;
391
391
  ni.neg = 0;
392
+ ni.no_big = (FloatDec == pi->options.bigdec_load);
392
393
 
393
394
  if ('-' == *pi->cur) {
394
395
  pi->cur++;
@@ -470,7 +471,7 @@ read_num(ParseInfo pi) {
470
471
  ni.dec_cnt -= zero_cnt;
471
472
  ni.len = pi->cur - ni.str;
472
473
  }
473
- if (Yes == pi->options.bigdec_load) {
474
+ if (BigDec == pi->options.bigdec_load) {
474
475
  ni.big = 1;
475
476
  }
476
477
  if (0 == parent) {
@@ -680,6 +681,9 @@ oj_num_as_value(NumInfo ni) {
680
681
  } else { // decimal
681
682
  if (ni->big) {
682
683
  rnum = rb_funcall(oj_bigdecimal_class, oj_new_id, 1, rb_str_new(ni->str, ni->len));
684
+ if (ni->no_big) {
685
+ rnum = rb_funcall(rnum, rb_intern("to_f"), 0);
686
+ }
683
687
  } else {
684
688
  double d = (double)ni->i + (double)ni->num / (double)ni->div;
685
689
 
@@ -50,6 +50,7 @@ typedef struct _NumInfo {
50
50
  int infinity;
51
51
  int nan;
52
52
  int neg;
53
+ int no_big;
53
54
  } *NumInfo;
54
55
 
55
56
  typedef struct _ParseInfo {
@@ -281,7 +281,8 @@ oj_sc_parse(int argc, VALUE *argv, VALUE self) {
281
281
  #endif
282
282
  } else if (rb_respond_to(input, oj_read_id)) {
283
283
  s = rb_funcall2(input, oj_read_id, 0, 0);
284
- pi.json = StringValuePtr(s);
284
+ pi.json = rb_string_value_cstr((VALUE*)&s);
285
+
285
286
  } else {
286
287
  rb_raise(rb_eArgError, "saj_parse() expected a String or IO Object.");
287
288
  }
@@ -36,8 +36,9 @@ mark(void *ptr) {
36
36
  ValStack stack = (ValStack)ptr;
37
37
  Val v;
38
38
 
39
- if (ptr == NULL) return;
40
-
39
+ if (0 == ptr) {
40
+ return;
41
+ }
41
42
  #if USE_PTHREAD_MUTEX
42
43
  pthread_mutex_lock(&stack->mutex);
43
44
  #elif USE_RB_MUTEX
@@ -1,5 +1,5 @@
1
1
 
2
2
  module Oj
3
3
  # Current version of the module.
4
- VERSION = '2.2.2'
4
+ VERSION = '2.2.3'
5
5
  end
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: UTF-8
3
+
4
+ # Ubuntu does not accept arguments to ruby when called using env. To get warnings to show up the -w options is
5
+ # required. That can be set in the RUBYOPT environment variable.
6
+ # export RUBYOPT=-w
7
+
8
+ $VERBOSE = true
9
+
10
+ $: << File.join(File.dirname(__FILE__), "../lib")
11
+ $: << File.join(File.dirname(__FILE__), "../ext")
12
+
13
+ require 'oj'
14
+
15
+ A = Struct.new(:a,:b,:c,:d)
16
+ B = Struct.new(:e,:f)
17
+
18
+ obj = [A.new(55, B.new(1, 'X'), B.new(2, 'Y'), 3)]
19
+
20
+ s = Oj.dump(obj, :mode => :object)
21
+
22
+ 100000.times do
23
+ Oj.load(s, :mode => :object)
24
+ # ds = Oj.dump(o, :mode => :object)
25
+ # if ds != s
26
+ # puts ds
27
+ # raise "holy crap"
28
+ # end
29
+ end
@@ -217,7 +217,7 @@ class ScpTest < ::Test::Unit::TestCase
217
217
  begin
218
218
  Oj.sc_parse(handler, json)
219
219
  rescue Exception => e
220
- assert_equal("unexpected character at line 1, column 6 [parse.c:636]", e.message)
220
+ assert_equal("unexpected character at line 1, column 6 [parse.c:637]", e.message)
221
221
  end
222
222
  end
223
223
 
@@ -133,7 +133,7 @@ class Juice < ::Test::Unit::TestCase
133
133
  :mode=>:object,
134
134
  :time_format=>:unix,
135
135
  :bigdecimal_as_decimal=>true,
136
- :bigdecimal_load=>false,
136
+ :bigdecimal_load=>:auto,
137
137
  :create_id=>'json_class'}, opts)
138
138
  end
139
139
 
@@ -149,7 +149,7 @@ class Juice < ::Test::Unit::TestCase
149
149
  :mode=>:object,
150
150
  :time_format=>:unix,
151
151
  :bigdecimal_as_decimal=>true,
152
- :bigdecimal_load=>false,
152
+ :bigdecimal_load=>:auto,
153
153
  :create_id=>'json_class'}
154
154
  o2 = {
155
155
  :indent=>4,
@@ -162,7 +162,7 @@ class Juice < ::Test::Unit::TestCase
162
162
  :mode=>:compat,
163
163
  :time_format=>:ruby,
164
164
  :bigdecimal_as_decimal=>false,
165
- :bigdecimal_load=>true,
165
+ :bigdecimal_load=>:bigdecimal,
166
166
  :create_id=>nil}
167
167
  o3 = { :indent => 4 }
168
168
  Oj.default_options = o2
@@ -826,6 +826,13 @@ class Juice < ::Test::Unit::TestCase
826
826
  assert_equal(BigDecimal, bg.class)
827
827
  assert_equal(orig, bg)
828
828
  end
829
+ def test_float_load
830
+ orig = BigDecimal.new('80.51')
831
+ json = Oj.dump(orig, :mode => :compat, :bigdecimal_as_decimal => true)
832
+ bg = Oj.load(json, :mode => :compat, :bigdecimal_load => :float)
833
+ assert_equal(Float, bg.class)
834
+ assert_equal(orig.to_f, bg)
835
+ end
829
836
  def test_bigdecimal_compat_to_json
830
837
  orig = BigDecimal.new('80.51')
831
838
  BigDecimal.send(:define_method, :to_json) do
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: 2.2.2
4
+ version: 2.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Ohler
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-11-17 00:00:00.000000000 Z
11
+ date: 2013-11-19 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: 'The fastest JSON parser and object serializer. '
14
14
  email: peter@ohler.com
@@ -83,6 +83,7 @@ files:
83
83
  - test/sample/text.rb
84
84
  - test/sample.rb
85
85
  - test/sample_json.rb
86
+ - test/struct.rb
86
87
  - test/test_compat.rb
87
88
  - test/test_fast.rb
88
89
  - test/test_gc.rb