- 1.0.0 (0)
- 1.1.6 (0)
- 1.2.6 (1)
- 2.0.3 (0)
- 2.1.0 (0)
- 2.2.1 (0)
- 2.3.8 (-1)
- 3.0.0 (0)
- 3.0.9 (38)
- 3.1.0 (-5)
- 3.2.1 (0)
- 3.2.8 (0)
- 3.2.13 (0)
- 4.0.2 (-33)
- 4.1.8 (0)
- 4.2.1 (0)
- 4.2.7 (0)
- 4.2.9 (0)
- 5.0.0.1 (12)
- 5.1.7 (0)
- 5.2.3 (11)
- 6.0.0 (-15)
- 6.1.3.1 (1)
- 6.1.7.7 (0)
- 7.0.0 (3)
- 7.1.3.2 (15)
- 7.1.3.4 (0)
- What's this?
frozen_string_literal: true
frozen_string_literal: true
The JSON gem adds a few modules to Ruby core classes containing :to_json definition, overwriting their default behavior. That said, we need to define the basic to_json method in all of them, otherwise they will always use to_json gem implementation, which is backwards incompatible in several cases (for instance, the JSON implementation for Hash does not work) with inheritance and consequently classes as ActiveSupport::OrderedHash cannot be serialized to json.
On the other hand, we should avoid conflict with ::JSON.{generate,dump}(obj). Unfortunately, the JSON gem’s encoder relies on its own to_json implementation to encode objects. Since it always passes a ::JSON::State object as the only argument to to_json, we can detect that and forward the calls to the original to_json method.
It should be noted that when using ::JSON.{generate,dump} directly, ActiveSupport’s encoder is bypassed completely. This means that as_json won’t be invoked and the JSON gem will simply ignore any options it does not natively understand. This also means that ::JSON.{generate,dump} should give exactly the same results with or without active support.
frozen_string_literal: true
frozen_string_literal: true
frozen_string_literal: true
frozen_string_literal: true
frozen_string_literal: true
frozen_string_literal: true
frozen_string_literal: true
frozen_string_literal: true
frozen_string_literal: true
frozen_string_literal: true
frozen_string_literal: true
frozen_string_literal: true
frozen_string_literal: true
frozen_string_literal: true
frozen_string_literal: true
frozen_string_literal: true
frozen_string_literal: true
frozen_string_literal: true
frozen_string_literal: true
frozen_string_literal: true
frozen_string_literal: true
frozen_string_literal: true
frozen_string_literal: true
frozen_string_literal: true
frozen_string_literal: true
frozen_string_literal: true
frozen_string_literal: true
frozen_string_literal: true
frozen_string_literal: true
frozen_string_literal: true
frozen_string_literal: true