oj 3.4.0 → 3.5.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 +5 -5
- data/README.md +1 -1
- data/ext/oj/compat.c +39 -5
- data/ext/oj/custom.c +37 -6
- data/ext/oj/dump_compat.c +11 -1
- data/ext/oj/dump_object.c +10 -0
- data/ext/oj/dump_strict.c +16 -0
- data/ext/oj/mimic_json.c +4 -3
- data/ext/oj/object.c +73 -28
- data/ext/oj/oj.c +10 -2
- data/ext/oj/oj.h +2 -0
- data/ext/oj/rails.c +11 -2
- data/ext/oj/saj.c +1 -1
- data/ext/oj/sparse.c +1 -26
- data/ext/oj/strict.c +55 -5
- data/ext/oj/trace.c +77 -0
- data/ext/oj/trace.h +26 -0
- data/ext/oj/wab.c +67 -7
- data/lib/oj/version.rb +1 -1
- data/pages/Encoding.md +3 -3
- data/pages/Modes.md +1 -0
- data/pages/Options.md +6 -1
- data/pages/Rails.md +27 -4
- data/test/activesupport5/encoding_test.rb +1 -0
- data/test/foo.rb +32 -0
- data/test/test_various.rb +1 -0
- metadata +15 -5
data/lib/oj/version.rb
CHANGED
data/pages/Encoding.md
CHANGED
@@ -10,7 +10,7 @@ in a JSON document. The formatting follows these rules.
|
|
10
10
|
* JSON native types, true, false, nil, String, Hash, Array, and Number are
|
11
11
|
encoded normally.
|
12
12
|
|
13
|
-
* A Symbol is encoded as a JSON string with a
|
13
|
+
* A Symbol is encoded as a JSON string with a preceding `':'` character.
|
14
14
|
|
15
15
|
* The `'^'` character denotes a special key value when in a JSON Object sequence.
|
16
16
|
|
@@ -28,7 +28,7 @@ in a JSON document. The formatting follows these rules.
|
|
28
28
|
* A `"^o"` JSON Object key indicates the value should be converted to a Ruby
|
29
29
|
Object. The first entry in the JSON Object must be a class with the `"^o"`
|
30
30
|
key. After that each entry is treated as a variable of the Object where the
|
31
|
-
key is the variable name without the
|
31
|
+
key is the variable name without the preceding `'@'`. An example is
|
32
32
|
`{"^o":"Oj::Bag","x":58,"y":"marbles"}`. `"^O"`is the same except that it
|
33
33
|
is for built in or odd classes that don't obey the normal Ruby
|
34
34
|
rules. Examples are Rational, Date, and DateTime.
|
@@ -40,7 +40,7 @@ in a JSON document. The formatting follows these rules.
|
|
40
40
|
`{"^u":["Range",1,7,false]}`.
|
41
41
|
|
42
42
|
* When encoding an Object, if the variable name does not begin with an
|
43
|
-
`'@'`character then the name
|
43
|
+
`'@'`character then the name preceded by a `'~'` character. This occurs in
|
44
44
|
the Exception class. An example is `{"^o":"StandardError","~mesg":"A
|
45
45
|
Message","~bt":[".\/tests.rb:345:in 'test_exception'"]}`.
|
46
46
|
|
data/pages/Modes.md
CHANGED
@@ -120,6 +120,7 @@ information.
|
|
120
120
|
| :space | String | | | x | x | | x | |
|
121
121
|
| :space_before | String | | | x | x | | x | |
|
122
122
|
| :symbol_keys | Boolean | x | x | x | x | x | x | |
|
123
|
+
| :trace | Boolean | x | x | x | x | x | x | x |
|
123
124
|
| :time_format | Symbol | | | | | x | x | |
|
124
125
|
| :use_as_json | Boolean | | | | | | x | |
|
125
126
|
| :use_to_hash | Boolean | | | | | | x | |
|
data/pages/Options.md
CHANGED
@@ -80,7 +80,7 @@ dynamically modifying classes or reloading classes then don't use this.
|
|
80
80
|
|
81
81
|
### :create_additions
|
82
82
|
|
83
|
-
A flag indicating the :create_id key when
|
83
|
+
A flag indicating the :create_id key when encountered during parsing should
|
84
84
|
creating an Object mactching the class name specified in the value associated
|
85
85
|
with the key.
|
86
86
|
|
@@ -226,6 +226,11 @@ compatibility. Using just indent as an integer gives better performance.
|
|
226
226
|
|
227
227
|
Use symbols instead of strings for hash keys. :symbolize_names is an alias.
|
228
228
|
|
229
|
+
### :trace
|
230
|
+
|
231
|
+
When true dump and load functions are traced by printing beginning and ending
|
232
|
+
of blocks and of specific calls.
|
233
|
+
|
229
234
|
### :time_format [Symbol]
|
230
235
|
|
231
236
|
The :time_format when dumping.
|
data/pages/Rails.md
CHANGED
@@ -20,6 +20,11 @@ or simply call
|
|
20
20
|
Oj.optimize_rails()
|
21
21
|
```
|
22
22
|
|
23
|
+
Either of those steps will setup Oj to mimic Rails but it will not change the
|
24
|
+
default mode type as the mode type is only used when calling the Oj encoding
|
25
|
+
directly. If Rails mode is also desired then use the `Oj.default_options` to
|
26
|
+
change the default mode.
|
27
|
+
|
23
28
|
Some of the Oj options are supported as arguments to the encoder if called
|
24
29
|
from Oj::Rails.encode() but when using the Oj::Rails::Encoder class the
|
25
30
|
encode() method does not support optional arguments as required by the
|
@@ -73,7 +78,7 @@ Oj::Rails.optimize is called with no arguments are:
|
|
73
78
|
* any other class where all attributes should be dumped
|
74
79
|
|
75
80
|
The ActiveSupport decoder is the JSON.parse() method. Calling the
|
76
|
-
Oj::Rails.set_decoder() method replaces that method with the Oj
|
81
|
+
Oj::Rails.set_decoder() method replaces that method with the Oj equivalent.
|
77
82
|
|
78
83
|
### Notes:
|
79
84
|
|
@@ -88,6 +93,24 @@ Oj::Rails.set_decoder() method replaces that method with the Oj equivelant.
|
|
88
93
|
are used as keys or if a other non-String objects such as Numerics are mixed
|
89
94
|
with numbers as Strings.
|
90
95
|
|
91
|
-
3. To verify Oj is being used turn on trace
|
92
|
-
|
93
|
-
|
96
|
+
3. To verify Oj is being used turn on the Oj `:trace` option. Similar to the
|
97
|
+
Ruby Tracer Oj will then print out trace information. Another approach is
|
98
|
+
to turn on C extension tracing. Set `tracer = TracePoint.new(:c_call) do
|
99
|
+
|tp| p [tp.lineno, tp.event, tp.defined_class, tp.method_id] end` or, in
|
100
|
+
older Rubies, set `Tracer.display_c_call = true`.
|
101
|
+
|
102
|
+
For example:
|
103
|
+
|
104
|
+
```
|
105
|
+
require 'active_support/core_ext'
|
106
|
+
require 'active_support/json'
|
107
|
+
require 'oj'
|
108
|
+
Oj.optimize_rails
|
109
|
+
tracer.enable { Time.now.to_json }
|
110
|
+
# prints output including
|
111
|
+
....
|
112
|
+
[20, :c_call, #<Class:Oj::Rails::Encoder>, :new]
|
113
|
+
[20, :c_call, Oj::Rails::Encoder, :encode]
|
114
|
+
....
|
115
|
+
=> "\"2018-02-23T12:13:42.493-06:00\""
|
116
|
+
```
|
data/test/foo.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
$: << '.'
|
4
|
+
$: << '../lib'
|
5
|
+
$: << '../ext'
|
6
|
+
|
7
|
+
require 'oj'
|
8
|
+
require 'sample'
|
9
|
+
|
10
|
+
#obj = sample_doc(1)
|
11
|
+
|
12
|
+
class Foo
|
13
|
+
def initialize()
|
14
|
+
@x = 'abc'
|
15
|
+
@y = 123
|
16
|
+
@a = [{}]
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
obj = Foo.new
|
21
|
+
obj = {
|
22
|
+
x: 'abc',
|
23
|
+
y: 123,
|
24
|
+
a: [{}]
|
25
|
+
}
|
26
|
+
|
27
|
+
j = Oj.dump(obj, mode: :rails, trace: true)
|
28
|
+
#j = Oj.dump(obj, mode: :compat)
|
29
|
+
|
30
|
+
puts j
|
31
|
+
|
32
|
+
Oj.load(j, mode: :rails, trace: true)
|
data/test/test_various.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.
|
4
|
+
version: 3.5.0
|
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-
|
11
|
+
date: 2018-03-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake-compiler
|
@@ -137,6 +137,8 @@ files:
|
|
137
137
|
- ext/oj/stream_writer.c
|
138
138
|
- ext/oj/strict.c
|
139
139
|
- ext/oj/string_writer.c
|
140
|
+
- ext/oj/trace.c
|
141
|
+
- ext/oj/trace.h
|
140
142
|
- ext/oj/val_stack.c
|
141
143
|
- ext/oj/val_stack.h
|
142
144
|
- ext/oj/wab.c
|
@@ -173,6 +175,7 @@ files:
|
|
173
175
|
- test/activesupport5/test_helper.rb
|
174
176
|
- test/activesupport5/time_zone_test_helpers.rb
|
175
177
|
- test/files.rb
|
178
|
+
- test/foo.rb
|
176
179
|
- test/helper.rb
|
177
180
|
- test/isolated/shared.rb
|
178
181
|
- test/isolated/test_mimic_after.rb
|
@@ -238,7 +241,13 @@ files:
|
|
238
241
|
homepage: http://www.ohler.com/oj
|
239
242
|
licenses:
|
240
243
|
- MIT
|
241
|
-
metadata:
|
244
|
+
metadata:
|
245
|
+
bug_tracker_uri: https://github.com/ohler55/oj/issues
|
246
|
+
changelog_uri: https://github.com/ohler55/oj/blob/master/CHANGELOG.md
|
247
|
+
documentation_uri: http://www.ohler.com/oj/doc/index.html
|
248
|
+
homepage_uri: http://www.ohler.com/oj/
|
249
|
+
source_code_uri: https://github.com/ohler55/oj
|
250
|
+
wiki_uri: https://github.com/ohler55/oj/wiki
|
242
251
|
post_install_message:
|
243
252
|
rdoc_options:
|
244
253
|
- "--title"
|
@@ -258,8 +267,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
258
267
|
- !ruby/object:Gem::Version
|
259
268
|
version: '0'
|
260
269
|
requirements: []
|
261
|
-
rubyforge_project:
|
262
|
-
rubygems_version: 2.
|
270
|
+
rubyforge_project:
|
271
|
+
rubygems_version: 2.7.3
|
263
272
|
signing_key:
|
264
273
|
specification_version: 4
|
265
274
|
summary: A fast JSON parser and serializer.
|
@@ -321,6 +330,7 @@ test_files:
|
|
321
330
|
- test/activesupport4/encoding_test.rb
|
322
331
|
- test/test_wab.rb
|
323
332
|
- test/perf_file.rb
|
333
|
+
- test/foo.rb
|
324
334
|
- test/perf_compat.rb
|
325
335
|
- test/test_various.rb
|
326
336
|
- test/test_strict.rb
|