File: Custom.md

package info (click to toggle)
ruby-oj 3.7.6-1
  • links: PTS, VCS
  • area: main
  • in suites: buster, sid
  • size: 1,508 kB
  • sloc: ansic: 16,262; ruby: 10,577; makefile: 2
file content (23 lines) | stat: -rw-r--r-- 1,227 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# Custom mode

The `:custom` mode is the most configurable mode and honors almost all
options. It provides the most flexibility although it can not be configured to
be exactly like any of the other modes. Each mode has some special aspect that
makes it unique. For example, the `:object` mode has it's own unique format
for object dumping and loading. The `:compat` mode mimic the json gem
including methods called for encoding and inconsistencies between
`JSON.dump()`, `JSON.generate()`, and `JSON()`.

The `:custom` mode is the default mode. It can be configured either by passing
options to the `Oj.dump()` and `Oj.load()` methods or by modifying the default
options.

The ability to create objects from JSON object elements is supported and
considers the `:create_additions` option. Special treatment is given to the
`:create_id` though. If the `:create_id` is set to `"^o"` then the Oj internal
encoding and decoding is used. These are more efficient than calling out to a
`to_json` method or `create_json` method on the classes. Those method do not
have to exist for the `"^o"` behavior to be utilized. Any other `:create_id`
value behaves similar to the json gem by calling `to_json` and `create_json`
as appropriate.