4
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

oj 2.18.0 の API変更対応

Posted at

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がdefault false になった
  • 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 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

4
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?