oj 2.13.1 → 2.14.0

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: 342383c1d1c0650dc81ad7a0f533e21b7ae67fa0
4
- data.tar.gz: 7ba24a6ed5411eaef0c539076f0396cbed856489
3
+ metadata.gz: 3c5b4c3cba3688cc740907e024a5c586dc87ee8e
4
+ data.tar.gz: 779f5f0c8ca3485a69099c63bb7e9048f7c3b1cd
5
5
  SHA512:
6
- metadata.gz: 0a80309e5fc8cd37f2d76f99567012697f5776f212bac9ffe38ee4bf4740853f19653cd49b4d0b7238688e89a857d28f7010a3ac5eaee576638175f63c8a3507
7
- data.tar.gz: 4a191f0f8294dde6558d24445b5f01eacf5276a68a823467caf32599ef6691c1523ed5253686372cee3e322dfdc845d2f88ccac471f9990605afa81a3f6edad7
6
+ metadata.gz: 35a08d84c9b2e4cef975627ab66cb92ae5db9f1f9baf45cb2a9a10ecb21f3c96c5f3db15b5abff775cfdb56f99fdad21e6d5e65c74a4fbc76061d2cc7d3bb977
7
+ data.tar.gz: 89a87edcd3f140d729dd0de077fcd9a9d39f39b29106a3fd247b8293a722241a31e4a7140962737b5222e98bd9f9898b55c0415d66bd504235251728258bc62b
data/README.md CHANGED
@@ -1,49 +1,42 @@
1
1
  # Oj gem
2
+ [![Build Status](https://secure.travis-ci.org/ohler55/oj.png?branch=master)](http://travis-ci.org/ohler55/oj)
3
+
2
4
  A fast JSON parser and Object marshaller as a Ruby gem.
3
5
 
6
+ ## Using
7
+
8
+ ```ruby
9
+ require 'oj'
10
+
11
+ h = { 'one' => 1, 'array' => [ true, false ] }
12
+ json = Oj.dump(h)
13
+
14
+ # json =
15
+ # {
16
+ # "one":1,
17
+ # "array":[
18
+ # true,
19
+ # false
20
+ # ]
21
+ # }
22
+
23
+ h2 = Oj.load(json)
24
+ puts "Same? #{h == h2}"
25
+ # true
26
+ ```
27
+
4
28
  ## Installation
5
29
  ```
6
30
  gem install oj
7
31
  ```
32
+
8
33
  or in Bundler:
34
+
9
35
  ```
10
36
  gem 'oj'
11
37
  ```
12
38
 
13
- ## Documentation
14
-
15
- *Documentation*: http://www.ohler.com/oj, http://rubydoc.info/gems/oj
16
-
17
- ## Source
18
-
19
- *GitHub* *repo*: https://github.com/ohler55/oj
20
-
21
- *RubyGems* *repo*: https://rubygems.org/gems/oj
22
-
23
- Follow [@peterohler on Twitter](http://twitter.com/#!/peterohler) for announcements and news about the Oj gem.
24
-
25
- ## Build Status
26
-
27
- [![Build Status](https://secure.travis-ci.org/ohler55/oj.png?branch=master)](http://travis-ci.org/ohler55/oj)
28
-
29
- ## Release 2.13.1
30
-
31
- - Thanks to Comboy for the fix to a large number rounding bug.
32
-
33
- ## Release 2.13.0
34
-
35
- - Oj no longer raises an exception if the to_hash method of an object does not
36
- return a Hash. ActiveRecord has decided that to_hash should return an Array
37
- instead so Oj now encodes what ever is returned.
38
-
39
- - Added a register_odd_raw function that allows odd marshal functions to return
40
- raw JSON as a string to be included in the dumped JSON.
41
-
42
- - The register_odd function now supports modules in additions to classes.
43
-
44
- [Older release notes](http://www.ohler.com/dev/oj_misc/release_notes.html).
45
-
46
- ## Description
39
+ ## Advanced
47
40
 
48
41
  Optimized JSON (Oj), as the name implies, was written to provide speed optimized
49
42
  JSON handling. It was designed as a faster alternative to Yajl and other
@@ -52,38 +45,139 @@ than any other Ruby JSON parser, and 3 or more times faster at serializing JSON.
52
45
 
53
46
  Oj has several `dump` or serialization modes which control how Ruby `Object`s are
54
47
  converted to JSON. These modes are set with the `:mode` option in either the
55
- default options or as one of the options to the `dump` method. The default mode
56
- is the `:object` mode.
48
+ default options or as one of the options to the `dump` method. In addition to
49
+ the various options there are also alternative APIs for parsing JSON.
57
50
 
58
- - `:strict` mode will only allow the 7 basic JSON types to be serialized. Any
59
- other `Object` will raise an `Exception`.
51
+ The fastest alternaive parser API is the `Oj::Doc` API. The `Oj::Doc` API takes
52
+ a completely different approach by opening a JSON document and providing calls
53
+ to navigate around the JSON while it is open. With this approach, JSON access
54
+ can be well over 20 times faster than conventional JSON parsing.
60
55
 
61
- - `:null` mode replaces any `Object` that is not one of the JSON types with a JSON `null`.
56
+ The `Oj::Saj` and `Oj::ScHandler` APIs are callback parsers that
57
+ walk the JSON document depth first and makes callbacks for each element.
58
+ Both callback parser are useful when only portions of the JSON are of
59
+ interest. Performance up to 20 times faster than conventional JSON is
60
+ possible if only a few elements of the JSON are of interest.
62
61
 
63
- - `:object` mode will dump any `Object` as a JSON `Object` with keys that match the
64
- Ruby `Object`'s variable names without the '@' prefix character. This is the highest
65
- performance mode.
62
+ ### Options
66
63
 
67
- - `:compat` mode attempts to be compatible with other systems. It will serialize any
68
- `Object`, but will check to see if the `Object` implements an `to_hash` or `to_json`
69
- method. If either exists, that method is used for serializing the `Object`.
70
- Since `as_json` is more flexible and produces more consistent output, it is
71
- preferred over the `to_json` method. If neither the `to_json` or `to_hash`
72
- methods exists, then the Oj internal `Object` variable encoding is used.
64
+ To change default serialization mode use the following form. Attempting to
65
+ modify the Oj.default_options Hash directly will not set the changes on the
66
+ actual default options but on a copy of the Hash:
73
67
 
74
- To change default serialization mode:
75
68
  ```ruby
76
69
  Oj.default_options = {:mode => :compat }
77
70
  ```
78
71
 
72
+ * `:mode` [Symbol] mode for dumping and loading JSON.
73
+
74
+ - `:object` mode will dump any `Object` as a JSON `Object` with keys that
75
+ match the Ruby `Object`'s variable names without the '@' prefix
76
+ character. This mode has the best performance and is the default.
77
+
78
+ - `:strict` mode will only allow the 7 basic JSON types to be serialized. Any
79
+ other `Object` will raise an `Exception`.
80
+
81
+ - `:null` mode replaces any `Object` that is not one of the JSON types with a JSON `null`.
82
+
83
+ - `:compat` mode attempts to be compatible with other systems. It will
84
+ serialize any `Object`, but will check to see if the `Object` implements an
85
+ `to_hash` or `to_json` method. If either exists, that method is used for
86
+ serializing the `Object`. Since `as_json` is more flexible and produces
87
+ more consistent output, it is preferred over the `to_json` method. If
88
+ neither the `to_json` or `to_hash` methods exists, then the Oj internal
89
+ `Object` variable encoding is used.
90
+
91
+ * `:indent` [Fixnum] number of spaces to indent each element in an JSON
92
+ document, zero is no newline between JSON elements, negative indicates no
93
+ newline between top level JSON elements in a stream
94
+
95
+ * `:circular` [Boolean] support circular references while dumping.
96
+
97
+ * `:auto_define` [Boolean] automatically define classes if they do not
98
+ exist.
99
+
100
+ * `:symbol_keys` [Boolean] use symbols instead of strings for hash keys.
101
+
102
+ * `:escape_mode` [Symbol] determines the characters to escape.
103
+
104
+ - `:newline` allows unescaped newlines in the output.
105
+
106
+ - `:json` follows the JSON specification. This is the default mode.
107
+
108
+ - `:xss_safe` escapes HTML and XML characters such as `&` and `<`.
109
+
110
+ - `:ascii` escapes all non-ascii or characters with the hi-bit set.
111
+
112
+ * `:class_cache` [Boolean] cache classes for faster parsing (if
113
+ dynamically modifying classes or reloading classes then don't use this)
114
+
115
+ * `:time_format` [Symbol] time format when dumping in :compat and :object mode
116
+
117
+ - `:unix` time is output as a decimal number in seconds since epoch including
118
+ fractions of a second.
119
+
120
+ - `:unix_zone` similar to the `:unix` format but with the timezone encoded in
121
+ the exponent of the decimal number of seconds since epoch.
122
+
123
+ - `:xmlschema` time is output as a string that follows the XML schema definition.
124
+
125
+ - `:ruby` time is output as a string formatted using the Ruby `to_s` conversion.
126
+
127
+ * `:bigdecimal_as_decimal` [Boolean] dump BigDecimal as a decimal number
128
+ or as a String
129
+
130
+ * `:bigdecimal_load` [Symbol] load decimals as BigDecimal instead of as a
131
+ Float.
132
+
133
+ - `:bigdecimal` convert all decimal numbers to BigDecimal.
134
+
135
+ - `:float` convert all decimal numbers to Float.
136
+
137
+ - `:auto` the most precise for the number of digits is used.
138
+
139
+ * `:create_id` [String] create id for json compatible object encoding,
140
+ default is `json_create`.
141
+
142
+ * `:second_precision` [Fixnum] number of digits after the decimal when dumping
143
+ the seconds portion of time
144
+
145
+ * `:float_precision` [Fixnum] number of digits of precision when dumping
146
+ floats, 0 indicates use Ruby
147
+
148
+ * `:use_to_json` [Boolean] call to_json() methods on dump, default is
149
+ false
150
+
151
+ * `:nilnil` [Boolean] if true a nil input to load will return nil and
152
+ not raise an Exception
153
+
154
+ * `:allow_gc` [Boolean] allow or prohibit GC during parsing, default is
155
+ true (allow).
156
+
157
+ * `:quirks_mode` [Boolean] Allow single JSON values instead of
158
+ documents, default is true (allow).
159
+
160
+ ## Releases
161
+
162
+ **Release 2.14.0**
163
+
164
+ - More tweaking on decimal rounding.
165
+
166
+ - Made dump options available in the default options and not only in the mimic
167
+ generate calls.
168
+
169
+ [Older release notes](http://www.ohler.com/dev/oj_misc/release_notes.html).
170
+
79
171
  ## Compatibility
80
172
 
81
- ### Ruby
82
- Oj is compatible with Ruby 1.8.7, 1.9.2, 1.9.3, 2.0.0, 2.1, 2.2 and RBX.
173
+ **Ruby**
174
+
175
+ Oj is compatible with Ruby 1.8.7, 1.9.2, 1.9.3, 2.0.0, 2.1, 2.2, 2.3 and RBX.
83
176
  Support for JRuby has been removed as JRuby no longer supports C extensions and
84
177
  there are bugs in the older versions that are not being fixed.
85
178
 
86
- ### Rails
179
+ **Rails**
180
+
87
181
  Although up until 4.1 Rails uses [multi_json](https://github.com/intridea/multi_json), an [issue in Rails](https://github.com/rails/rails/issues/9212) causes ActiveSupport to fail to make use Oj for JSON handling.
88
182
  There is a
89
183
  [gem to patch this](https://github.com/GoodLife/rails-patch-json-encode) for
@@ -92,72 +186,51 @@ the `to_json()` method unless the `:use_to_json` option is set. This provides
92
186
  another work around to the rails older and newer behavior.
93
187
 
94
188
  The latest ActiveRecord is able to work with Oj by simply using the line:
189
+
95
190
  ```
96
- serialize :my_attr, Oj
191
+ serialize :metadata, Oj
97
192
  ```
98
193
 
99
194
  In version Rails 4.1, multi_json has been removed, and this patch is unnecessary and will no longer work.
100
195
  Instead, use the `oj_mimic_json` [gem](https://github.com/ohler55/oj_mimic_json) along with `oj` in your `Gemfile` to have Oj mimic the JSON gem and be used in its place by `ActiveSupport` JSON handling:
196
+
101
197
  ```
102
198
  gem 'oj'
103
199
  gem 'oj_mimic_json'
104
200
  ```
105
201
 
106
- ## Proper Use
107
-
108
- Two settings in Oj are useful for parsing but do expose a vulnerability if used from an untrusted source. Symbolized
109
- keys can cause memory to be filled with previous versions of ruby. Ruby 2.1 and below does not garbage collect Symbols. The same is true for auto
110
- defining classes in all versions of ruby; memory will also be exhausted if too many classes are automatically defined. Auto defining is a useful
111
- feature during development and from trusted sources but it allows too many classes to be created in the object load
112
- mode and auto defined is used with an untrusted source. The `Oj.strict_load()` method sets and uses the most strict and safest options. It should be used by developers who find it difficult to understand the options available in Oj.
113
-
114
- The options in Oj are designed to provide flexibility to the developer. This flexibility allows Objects to be serialized
115
- and deserialized. No methods are ever called on these created Objects but that does not stop the developer from calling
116
- methods on them. As in any system, check your inputs before working with them. Taking an arbitrary `String`
117
- from a user and evaluating it is never a good idea from an unsecure source. The same is true for `Object` attributes as
118
- they are not more than `String`s. Always check inputs from untrusted sources.
119
-
120
-
121
- ## Simple JSON Writing and Parsing Example
122
-
123
- ```ruby
124
- require 'oj'
125
-
126
- h = { 'one' => 1, 'array' => [ true, false ] }
127
- json = Oj.dump(h)
128
-
129
- # json =
130
- # {
131
- # "one":1,
132
- # "array":[
133
- # true,
134
- # false
135
- # ]
136
- # }
137
-
138
- h2 = Oj.load(json)
139
- puts "Same? #{h == h2}"
140
- # true
141
- ```
142
-
143
- ## Alternative JSON Processing APIs
202
+ ## Security and Optimization
203
+
204
+ Two settings in Oj are useful for parsing but do expose a vulnerability if used
205
+ from an untrusted source. Symbolized keys can cause memory to be filled with
206
+ previous versions of ruby. Ruby 2.1 and below does not garbage collect
207
+ Symbols. The same is true for auto defining classes in all versions of ruby;
208
+ memory will also be exhausted if too many classes are automatically
209
+ defined. Auto defining is a useful feature during development and from trusted
210
+ sources but it allows too many classes to be created in the object load mode and
211
+ auto defined is used with an untrusted source. The `Oj.strict_load()` method
212
+ sets and uses the most strict and safest options. It should be used by
213
+ developers who find it difficult to understand the options available in Oj.
214
+
215
+ The options in Oj are designed to provide flexibility to the developer. This
216
+ flexibility allows Objects to be serialized and deserialized. No methods are
217
+ ever called on these created Objects but that does not stop the developer from
218
+ calling methods on them. As in any system, check your inputs before working with
219
+ them. Taking an arbitrary `String` from a user and evaluating it is never a good
220
+ idea from an unsecure source. The same is true for `Object` attributes as they
221
+ are not more than `String`s. Always check inputs from untrusted sources.
222
+
223
+ ## Links
144
224
 
145
- Oj offers a few alternative APIs for processing JSON. The fastest one is the `Oj::Doc` API. The `Oj::Doc` API takes a
146
- completely different approach by opening a JSON document and providing calls to navigate around the JSON while it is
147
- open. With this approach, JSON access can be well over 20 times faster than conventional JSON parsing.
225
+ *Documentation*: http://www.ohler.com/oj, http://rubydoc.info/gems/oj
148
226
 
149
- The `Oj::Saj` and `Oj::ScHandler` APIs are callback parsers that
150
- walk the JSON document depth first and makes callbacks for each element.
151
- Both callback parser are useful when only portions of the JSON are of
152
- interest. Performance up to 20 times faster than conventional JSON is
153
- possible. The API is simple to use but does require a different approach than
154
- the conventional parse followed by access approach used by conventional JSON
155
- parsing.
227
+ *GitHub* *repo*: https://github.com/ohler55/oj
156
228
 
229
+ *RubyGems* *repo*: https://rubygems.org/gems/oj
157
230
 
158
- # Links
231
+ Follow [@peterohler on Twitter](http://twitter.com/#!/peterohler) for announcements and news about the Oj gem.
159
232
 
160
- ## Performance Comparisons
233
+ #### Performance Comparisons
161
234
 
162
235
  [Oj Strict Mode Performance](http://www.ohler.com/dev/oj_misc/performance_strict.html) compares Oj strict mode parser performance to other JSON parsers.
163
236
 
@@ -167,7 +240,7 @@ parsing.
167
240
 
168
241
  [Oj Callback Performance](http://www.ohler.com/dev/oj_misc/performance_callback.html) compares Oj callback parser performance to other JSON parsers.
169
242
 
170
- ## Links of Interest
243
+ #### Links of Interest
171
244
 
172
245
  *Fast XML parser and marshaller on RubyGems*: https://rubygems.org/gems/ox
173
246
 
@@ -703,30 +703,30 @@ dump_array(VALUE a, VALUE clas, int depth, Out out) {
703
703
  if (0 < id) {
704
704
  *out->cur++ = ',';
705
705
  }
706
- if (0 == out->opts->dump_opts) {
707
- size = d2 * out->indent + 2;
706
+ if (out->opts->dump_opts.use) {
707
+ size = d2 * out->opts->dump_opts.indent_size + out->opts->dump_opts.array_size + 1;
708
708
  } else {
709
- size = d2 * out->opts->dump_opts->indent_size + out->opts->dump_opts->array_size + 1;
709
+ size = d2 * out->indent + 2;
710
710
  }
711
711
  cnt--;
712
712
  for (i = 0; i <= cnt; i++) {
713
713
  if (out->end - out->cur <= (long)size) {
714
714
  grow(out, size);
715
715
  }
716
- if (0 == out->opts->dump_opts) {
717
- fill_indent(out, d2);
718
- } else {
719
- if (0 < out->opts->dump_opts->array_size) {
720
- strcpy(out->cur, out->opts->dump_opts->array_nl);
721
- out->cur += out->opts->dump_opts->array_size;
716
+ if (out->opts->dump_opts.use) {
717
+ if (0 < out->opts->dump_opts.array_size) {
718
+ strcpy(out->cur, out->opts->dump_opts.array_nl);
719
+ out->cur += out->opts->dump_opts.array_size;
722
720
  }
723
- if (0 < out->opts->dump_opts->indent_size) {
721
+ if (0 < out->opts->dump_opts.indent_size) {
724
722
  int i;
725
723
  for (i = d2; 0 < i; i--) {
726
- strcpy(out->cur, out->opts->dump_opts->indent);
727
- out->cur += out->opts->dump_opts->indent_size;
724
+ strcpy(out->cur, out->opts->dump_opts.indent_str);
725
+ out->cur += out->opts->dump_opts.indent_size;
728
726
  }
729
727
  }
728
+ } else {
729
+ fill_indent(out, d2);
730
730
  }
731
731
  dump_val(rb_ary_entry(a, i), d2, out, 0, 0);
732
732
  if (i < cnt) {
@@ -737,22 +737,22 @@ dump_array(VALUE a, VALUE clas, int depth, Out out) {
737
737
  if (out->end - out->cur <= (long)size) {
738
738
  grow(out, size);
739
739
  }
740
- if (0 == out->opts->dump_opts) {
741
- fill_indent(out, depth);
742
- } else {
740
+ if (out->opts->dump_opts.use) {
743
741
  //printf("*** d2: %u indent: %u '%s'\n", d2, out->opts->dump_opts->indent_size, out->opts->dump_opts->indent);
744
- if (0 < out->opts->dump_opts->array_size) {
745
- strcpy(out->cur, out->opts->dump_opts->array_nl);
746
- out->cur += out->opts->dump_opts->array_size;
742
+ if (0 < out->opts->dump_opts.array_size) {
743
+ strcpy(out->cur, out->opts->dump_opts.array_nl);
744
+ out->cur += out->opts->dump_opts.array_size;
747
745
  }
748
- if (0 < out->opts->dump_opts->indent_size) {
746
+ if (0 < out->opts->dump_opts.indent_size) {
749
747
  int i;
750
748
 
751
749
  for (i = depth; 0 < i; i--) {
752
- strcpy(out->cur, out->opts->dump_opts->indent);
753
- out->cur += out->opts->dump_opts->indent_size;
750
+ strcpy(out->cur, out->opts->dump_opts.indent_str);
751
+ out->cur += out->opts->dump_opts.indent_size;
754
752
  }
755
753
  }
754
+ } else {
755
+ fill_indent(out, depth);
756
756
  }
757
757
  *out->cur++ = ']';
758
758
  }
@@ -767,7 +767,7 @@ hash_cb_strict(VALUE key, VALUE value, Out out) {
767
767
  if (rb_type(key) != T_STRING) {
768
768
  rb_raise(rb_eTypeError, "In :strict mode all Hash keys must be Strings, not %s.\n", rb_class2name(rb_obj_class(key)));
769
769
  }
770
- if (0 == out->opts->dump_opts) {
770
+ if (!out->opts->dump_opts.use) {
771
771
  size = depth * out->indent + 1;
772
772
  if (out->end - out->cur <= size) {
773
773
  grow(out, size);
@@ -776,34 +776,34 @@ hash_cb_strict(VALUE key, VALUE value, Out out) {
776
776
  dump_str_comp(key, out);
777
777
  *out->cur++ = ':';
778
778
  } else {
779
- size = depth * out->opts->dump_opts->indent_size + out->opts->dump_opts->hash_size + 1;
779
+ size = depth * out->opts->dump_opts.indent_size + out->opts->dump_opts.hash_size + 1;
780
780
  if (out->end - out->cur <= size) {
781
781
  grow(out, size);
782
782
  }
783
- if (0 < out->opts->dump_opts->hash_size) {
784
- strcpy(out->cur, out->opts->dump_opts->hash_nl);
785
- out->cur += out->opts->dump_opts->hash_size;
783
+ if (0 < out->opts->dump_opts.hash_size) {
784
+ strcpy(out->cur, out->opts->dump_opts.hash_nl);
785
+ out->cur += out->opts->dump_opts.hash_size;
786
786
  }
787
- if (0 < out->opts->dump_opts->indent_size) {
787
+ if (0 < out->opts->dump_opts.indent_size) {
788
788
  int i;
789
789
  for (i = depth; 0 < i; i--) {
790
- strcpy(out->cur, out->opts->dump_opts->indent);
791
- out->cur += out->opts->dump_opts->indent_size;
790
+ strcpy(out->cur, out->opts->dump_opts.indent_str);
791
+ out->cur += out->opts->dump_opts.indent_size;
792
792
  }
793
793
  }
794
794
  dump_str_comp(key, out);
795
- size = out->opts->dump_opts->before_size + out->opts->dump_opts->after_size + 2;
795
+ size = out->opts->dump_opts.before_size + out->opts->dump_opts.after_size + 2;
796
796
  if (out->end - out->cur <= size) {
797
797
  grow(out, size);
798
798
  }
799
- if (0 < out->opts->dump_opts->before_size) {
800
- strcpy(out->cur, out->opts->dump_opts->before_sep);
801
- out->cur += out->opts->dump_opts->before_size;
799
+ if (0 < out->opts->dump_opts.before_size) {
800
+ strcpy(out->cur, out->opts->dump_opts.before_sep);
801
+ out->cur += out->opts->dump_opts.before_size;
802
802
  }
803
803
  *out->cur++ = ':';
804
- if (0 < out->opts->dump_opts->after_size) {
805
- strcpy(out->cur, out->opts->dump_opts->after_sep);
806
- out->cur += out->opts->dump_opts->after_size;
804
+ if (0 < out->opts->dump_opts.after_size) {
805
+ strcpy(out->cur, out->opts->dump_opts.after_sep);
806
+ out->cur += out->opts->dump_opts.after_size;
807
807
  }
808
808
  }
809
809
  dump_val(value, depth, out, 0, 0);
@@ -818,26 +818,26 @@ hash_cb_compat(VALUE key, VALUE value, Out out) {
818
818
  int depth = out->depth;
819
819
  long size;
820
820
 
821
- if (0 == out->opts->dump_opts) {
821
+ if (!out->opts->dump_opts.use) {
822
822
  size = depth * out->indent + 1;
823
823
  if (out->end - out->cur <= size) {
824
824
  grow(out, size);
825
825
  }
826
826
  fill_indent(out, depth);
827
827
  } else {
828
- size = depth * out->opts->dump_opts->indent_size + out->opts->dump_opts->hash_size + 1;
828
+ size = depth * out->opts->dump_opts.indent_size + out->opts->dump_opts.hash_size + 1;
829
829
  if (out->end - out->cur <= size) {
830
830
  grow(out, size);
831
831
  }
832
- if (0 < out->opts->dump_opts->hash_size) {
833
- strcpy(out->cur, out->opts->dump_opts->hash_nl);
834
- out->cur += out->opts->dump_opts->hash_size;
832
+ if (0 < out->opts->dump_opts.hash_size) {
833
+ strcpy(out->cur, out->opts->dump_opts.hash_nl);
834
+ out->cur += out->opts->dump_opts.hash_size;
835
835
  }
836
- if (0 < out->opts->dump_opts->indent_size) {
836
+ if (0 < out->opts->dump_opts.indent_size) {
837
837
  int i;
838
838
  for (i = depth; 0 < i; i--) {
839
- strcpy(out->cur, out->opts->dump_opts->indent);
840
- out->cur += out->opts->dump_opts->indent_size;
839
+ strcpy(out->cur, out->opts->dump_opts.indent_str);
840
+ out->cur += out->opts->dump_opts.indent_size;
841
841
  }
842
842
  }
843
843
  }
@@ -853,21 +853,21 @@ hash_cb_compat(VALUE key, VALUE value, Out out) {
853
853
  dump_str_comp(rb_funcall(key, oj_to_s_id, 0), out);
854
854
  break;
855
855
  }
856
- if (0 == out->opts->dump_opts) {
856
+ if (!out->opts->dump_opts.use) {
857
857
  *out->cur++ = ':';
858
858
  } else {
859
- size = out->opts->dump_opts->before_size + out->opts->dump_opts->after_size + 2;
859
+ size = out->opts->dump_opts.before_size + out->opts->dump_opts.after_size + 2;
860
860
  if (out->end - out->cur <= size) {
861
861
  grow(out, size);
862
862
  }
863
- if (0 < out->opts->dump_opts->before_size) {
864
- strcpy(out->cur, out->opts->dump_opts->before_sep);
865
- out->cur += out->opts->dump_opts->before_size;
863
+ if (0 < out->opts->dump_opts.before_size) {
864
+ strcpy(out->cur, out->opts->dump_opts.before_sep);
865
+ out->cur += out->opts->dump_opts.before_size;
866
866
  }
867
867
  *out->cur++ = ':';
868
- if (0 < out->opts->dump_opts->after_size) {
869
- strcpy(out->cur, out->opts->dump_opts->after_sep);
870
- out->cur += out->opts->dump_opts->after_size;
868
+ if (0 < out->opts->dump_opts.after_size) {
869
+ strcpy(out->cur, out->opts->dump_opts.after_sep);
870
+ out->cur += out->opts->dump_opts.after_size;
871
871
  }
872
872
  }
873
873
  dump_val(value, depth, out, 0, 0);
@@ -988,26 +988,26 @@ dump_hash(VALUE obj, VALUE clas, int depth, int mode, Out out) {
988
988
  if (',' == *(out->cur - 1)) {
989
989
  out->cur--; // backup to overwrite last comma
990
990
  }
991
- if (0 == out->opts->dump_opts) {
991
+ if (!out->opts->dump_opts.use) {
992
992
  if (out->end - out->cur <= (long)size) {
993
993
  grow(out, size);
994
994
  }
995
995
  fill_indent(out, depth);
996
996
  } else {
997
- size = depth * out->opts->dump_opts->indent_size + out->opts->dump_opts->hash_size + 1;
997
+ size = depth * out->opts->dump_opts.indent_size + out->opts->dump_opts.hash_size + 1;
998
998
  if (out->end - out->cur <= (long)size) {
999
999
  grow(out, size);
1000
1000
  }
1001
- if (0 < out->opts->dump_opts->hash_size) {
1002
- strcpy(out->cur, out->opts->dump_opts->hash_nl);
1003
- out->cur += out->opts->dump_opts->hash_size;
1001
+ if (0 < out->opts->dump_opts.hash_size) {
1002
+ strcpy(out->cur, out->opts->dump_opts.hash_nl);
1003
+ out->cur += out->opts->dump_opts.hash_size;
1004
1004
  }
1005
- if (0 < out->opts->dump_opts->indent_size) {
1005
+ if (0 < out->opts->dump_opts.indent_size) {
1006
1006
  int i;
1007
1007
 
1008
1008
  for (i = depth; 0 < i; i--) {
1009
- strcpy(out->cur, out->opts->dump_opts->indent);
1010
- out->cur += out->opts->dump_opts->indent_size;
1009
+ strcpy(out->cur, out->opts->dump_opts.indent_str);
1010
+ out->cur += out->opts->dump_opts.indent_size;
1011
1011
  }
1012
1012
  }
1013
1013
  }