TL;DR
- oj 2.18.0 で
This changes the API slightly.
な変更が入った
Added a separate option for as_json instead of piggy backing on the use_to_json. This changes the API slightly.
-
to_json
をcallするoptionがdefaultfalse
になった -
to_json
のcallを期待する場合は、都度指定するか defualt optionを設定するとよい
default option
require 'oj'
::Oj.default_options = {:mode => :compat, use_to_json: true }
::Oj.dump(value)
都度
require 'oj'
::Oj.dump(value, :mode => :compat, use_to_json: true)
Ref
-
:compatモードについて
:compat mode attempts to be compatible with other systems. It will serialize any Object, but will check to see if the Object implements an to_hash or to_json method. If either exists, that method is used for serializing the Object. Since as_json is more flexible and produces more consistent output, it is preferred over the to_json method. If neither the to_json or to_hash methods exists, then the Oj internal Object variable encoding is used.
- use_to_jsonについて
:use_to_json [Boolean] call to_json() methods on dump, default is false