oj 3.6.3 → 3.6.4

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
  SHA256:
3
- metadata.gz: e3bd53d19ca0596197ef568e62ecd42cc06bf50da464f3d12e8c930a8b522e63
4
- data.tar.gz: c86a9bb989dda968386361ef7ec598d60728f135fc4215d94155e86c560f7236
3
+ metadata.gz: e19d294e6f097eaef9b3a336ad95728690cab3875f155f922ffe18857713be8f
4
+ data.tar.gz: 0d6090bbe88e53d9d33eea3dad09c8f1d3163b925ea39ef8ff927919568ce9b1
5
5
  SHA512:
6
- metadata.gz: 6f5db14003bb717967c40273ea6e2dc3d2605490fa54c3b9130ba7543bc3ce8b36aa86f1ea514d6c509ffd1313f4ed88dae32326a0585c84407cd1e3c0275220
7
- data.tar.gz: 302da9f08e30fe0c6bd5f3aeea668328975d4f153befd4812b1c3b50a8720d6d255f216e8bb22451672947d23f3c0fa3d7837415813950f87717b02a0238d291
6
+ metadata.gz: 3b5168386d95712f0b936819d6c8a3409c86d1ef6dda60cf3447adf222edfc4040b8c3e047b5af327064e6598b79d0a48f94724ac0660bf8fcb5e40bea6e6c49
7
+ data.tar.gz: 3cc4309e5248d9c9e7bcd993cb6cad207de40e0b0d6230e1175cbe9f6fc6cd05f6ce48d2522056bc566e7d8f88500ecb1124a73eda23cc04be4c81b292bb7e92
@@ -189,6 +189,7 @@ dump_array(VALUE a, int depth, Out out, bool as_ok) {
189
189
  } else {
190
190
  fill_indent(out, d2);
191
191
  }
192
+ // TBD for child as_ok check the type, time is to_s while others are to_json
192
193
  oj_dump_compat_val(rb_ary_entry(a, i), d2, out, true);
193
194
  if (i < cnt) {
194
195
  *out->cur++ = ',';
@@ -370,6 +370,7 @@ mimic_generate_core(int argc, VALUE *argv, Options copts) {
370
370
  // it is.
371
371
  copts->dump_opts.nan_dump = RaiseNan;
372
372
  copts->mode = CompatMode;
373
+ copts->to_json = Yes;
373
374
  if (2 == argc && Qnil != argv[1]) {
374
375
  oj_parse_mimic_dump_options(argv[1], copts);
375
376
  }
@@ -858,9 +859,6 @@ oj_define_mimic_json(int argc, VALUE *argv, VALUE self) {
858
859
  rb_funcall2(Oj, rb_intern("mimic_loaded"), 0, 0);
859
860
  }
860
861
  }
861
-
862
- // TBD create all modules in mimic_loaded
863
-
864
862
  oj_mimic_json_methods(json);
865
863
 
866
864
  rb_define_method(rb_cObject, "to_json", mimic_object_to_json, -1);
@@ -229,6 +229,7 @@ struct _Options oj_default_options = {
229
229
  * - *:bigdecimal_as_decimal* [_Boolean_|_nil_] dump BigDecimal as a decimal number or as a String
230
230
  * - *:bigdecimal_load* [_:bigdecimal_|_:float_|_:auto_] load decimals as BigDecimal instead of as a Float. :auto pick the most precise for the number of digits.
231
231
  * - *:create_id* [_String_|_nil_] create id for json compatible object encoding, default is 'json_class'
232
+ * - *:create_additions* [_Boolean_|_nil_] if true allow creation of instances using create_id on load.
232
233
  * - *:second_precision* [_Fixnum_|_nil_] number of digits after the decimal when dumping the seconds portion of time
233
234
  * - *:float_precision* [_Fixnum_|_nil_] number of digits of precision when dumping floats, 0 indicates use Ruby
234
235
  * - *:use_to_json* [_Boolean_|_nil_] call to_json() methods on dump, default is false
@@ -268,6 +269,7 @@ get_def_opts(VALUE self) {
268
269
  rb_hash_aset(opts, auto_define_sym, (Yes == oj_default_options.auto_define) ? Qtrue : ((No == oj_default_options.auto_define) ? Qfalse : Qnil));
269
270
  rb_hash_aset(opts, symbol_keys_sym, (Yes == oj_default_options.sym_key) ? Qtrue : ((No == oj_default_options.sym_key) ? Qfalse : Qnil));
270
271
  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));
272
+ rb_hash_aset(opts, oj_create_additions_sym, (Yes == oj_default_options.create_ok) ? Qtrue : ((No == oj_default_options.create_ok) ? Qfalse : Qnil));
271
273
  rb_hash_aset(opts, use_to_json_sym, (Yes == oj_default_options.to_json) ? Qtrue : ((No == oj_default_options.to_json) ? Qfalse : Qnil));
272
274
  rb_hash_aset(opts, use_to_hash_sym, (Yes == oj_default_options.to_hash) ? Qtrue : ((No == oj_default_options.to_hash) ? Qfalse : Qnil));
273
275
  rb_hash_aset(opts, use_as_json_sym, (Yes == oj_default_options.as_json) ? Qtrue : ((No == oj_default_options.as_json) ? Qfalse : Qnil));
@@ -358,6 +360,7 @@ get_def_opts(VALUE self) {
358
360
  * - *:mode* [_:object_|_:strict_|_:compat_|_:null_|_:custom_|_:rails_|_:wab_] load and dump mode to use for JSON :strict raises an exception when a non-supported Object is encountered. :compat attempts to extract variable values from an Object using to_json() or to_hash() then it walks the Object's variables if neither is found. The :object mode ignores to_hash() and to_json() methods and encodes variables using code internal to the Oj gem. The :null mode ignores non-supported Objects and replaces them with a null. The :custom mode honors all dump options. The :rails more mimics rails and Active behavior.
359
361
  * - *:time_format* [_:unix_|_:xmlschema_|_:ruby_] time format when dumping in :compat mode :unix decimal number denoting the number of seconds since 1/1/1970, :unix_zone decimal number denoting the number of seconds since 1/1/1970 plus the utc_offset in the exponent, :xmlschema date-time format taken from XML Schema as a String, :ruby Time.to_s formatted String.
360
362
  * - *:create_id* [_String_|_nil_] create id for json compatible object encoding
363
+ * - *:create_additions* [_Boolean_|_nil_] if true allow creation of instances using create_id on load.
361
364
  * - *:second_precision* [_Fixnum_|_nil_] number of digits after the decimal when dumping the seconds portion of time.
362
365
  * - *:float_precision* [_Fixnum_|_nil_] number of digits of precision when dumping floats, 0 indicates use Ruby.
363
366
  * - *:use_to_json* [_Boolean_|_nil_] call to_json() methods on dump, default is false.
@@ -823,6 +823,7 @@ rails_mimic_json(VALUE self) {
823
823
  json = rb_define_module("JSON");
824
824
  }
825
825
  oj_mimic_json_methods(json);
826
+ oj_default_options.mode = RailsMode;
826
827
 
827
828
  return Qnil;
828
829
  }
@@ -1,5 +1,5 @@
1
1
 
2
2
  module Oj
3
3
  # Current version of the module.
4
- VERSION = '3.6.3'
4
+ VERSION = '3.6.4'
5
5
  end
@@ -4,33 +4,64 @@ $: << '.'
4
4
  $: << '../lib'
5
5
  $: << '../ext'
6
6
 
7
- require 'tracer'
8
- require 'oj'
9
- require 'sample'
7
+ require 'active_support'
8
+ require 'active_support/core_ext'
9
+ require 'active_support/json/encoding.rb'
10
+ require 'json'
10
11
 
11
12
  class Foo
12
- def initialize()
13
- @x = 'abc'
14
- @y = 123
15
- @a = [{}]
16
- end
17
-
18
- def to_json()
19
- '{"x":33}'
13
+ def to_json(*)
14
+ '{"foo":"bar"}'
20
15
  end
16
+ end
21
17
 
22
- def as_json(options={})
23
- { z: @a, y: @y, x: @x }
18
+ class Dub
19
+ def initialize(a,b)
20
+ @a = a
21
+ @b = b
24
22
  end
25
23
  end
26
24
 
27
- Tracer.display_c_call = true
28
- Tracer.on
25
+ puts "*** time respond to: #{Time.now.utc.respond_to?(:to_json)}"
26
+
27
+ hash_with_time = { foo: Time.now.utc }
28
+ boo = { boo: Time.now.utc, foo: Foo.new, dub: Dub.new(1,2) }
29
+ aaa = [Time.now.utc, Foo.new, Dub.new(1,2)]
30
+
31
+ puts "*** boo #{JSON.generate(boo)}"
32
+ puts "*** aaa #{JSON.generate(aaa)}"
33
+
34
+ puts "*** time: #{Time.now.utc.to_json}"
35
+
36
+ puts hash_with_time.to_json
37
+ # => {"foo":"2018-06-28T09:07:40.464Z"}
38
+ puts JSON.generate(hash_with_time)
39
+ # => {"foo":"2018-06-28 09:07:40 UTC"}
40
+
41
+
42
+ puts JSON.generate({ foo: Foo.new }.with_indifferent_access)
43
+ puts JSON.generate({ foo: Foo.new })
44
+ # => {"foo":{"foo":"bar"}}
45
+ puts({ foo: Foo.new }.to_json)
46
+ # => {"foo":{}}
47
+
48
+ puts "-------------------"
49
+ require 'oj'
29
50
 
30
- obj = Foo.new
51
+ #Oj.optimize_rails
52
+ Oj.mimic_JSON
31
53
 
32
- j = Oj.dump(obj, mode: :custom, trace: true, use_as_json: true)
54
+ puts "*** boo #{JSON.generate(boo)}"
33
55
 
34
- #puts j
56
+ Oj.default_options = {trace: true}
57
+ puts hash_with_time.to_json
58
+ # => {"foo":"2018-06-28T09:07:40.464Z"}
59
+ puts JSON.generate(hash_with_time)
60
+ # => {"foo":"2018-06-28T09:07:40.464Z"}
61
+ puts hash_with_time.to_json
35
62
 
36
- #Oj.load(j, mode: :rails, trace: true)
63
+ puts JSON.generate({ foo: Foo.new }.with_indifferent_access)
64
+ puts JSON.generate({ foo: Foo.new })
65
+ # => {"foo":{}}
66
+ puts({ foo: Foo.new }.to_json)
67
+ # => {"foo":{}}
@@ -145,6 +145,7 @@ class Juice < Minitest::Test
145
145
  :time_format=>:unix_zone,
146
146
  :bigdecimal_load=>:float,
147
147
  :create_id=>'classy',
148
+ :create_additions=>true,
148
149
  :space=>'z',
149
150
  :array_nl=>'a',
150
151
  :object_nl=>'o',
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.6.3
4
+ version: 3.6.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Ohler
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-06-21 00:00:00.000000000 Z
11
+ date: 2018-07-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake-compiler