class OjSerializers::JsonValue

Public: Allows to prevent double encoding an existing JSON string.

NOTE: Oj's raw_json option means there's no performance overhead, as it would occur with the previous alternative of parsing the JSON string.

Public Class Methods

array(json_rows) click to toggle source

Helper: Expects an Array of JSON-encoded strings and wraps them in a JSON array.

# File lib/oj_serializers/json_value.rb, line 9
def self.array(json_rows)
  new("[#{json_rows.join(',')}]")
end
new(json) click to toggle source
# File lib/oj_serializers/json_value.rb, line 13
def initialize(json)
  @json = json
end

Public Instance Methods

as_json(_options = nil) click to toggle source

Internal: Used by Oj::Rails::Encoder when found inside a Hash or Array.

# File lib/oj_serializers/json_value.rb, line 28
def as_json(_options = nil)
  self
end
raw_json(*) click to toggle source

Internal: Used by Oj::Rails::Encoder because we use the `raw_json` option.

# File lib/oj_serializers/json_value.rb, line 23
def raw_json(*)
  @json
end
to_s() click to toggle source

Public: Return the internal json when using string interpolation.

# File lib/oj_serializers/json_value.rb, line 18
def to_s
  @json
end