Class: Gitlab::Json::RailsEncoder

Inherits:
ActiveSupport::JSON::Encoding::JSONGemEncoder
  • Object
show all
Defined in:
lib/gitlab/json.rb

Instance Method Summary collapse

Instance Method Details

#stringify(jsonified) ⇒ Object

Rails doesn’t provide a way of changing the JSON adapter for render calls in controllers, so here we’re overriding the parent class method to use our generator, and it’s monkey-patched in config/initializers/active_support_json.rb



265
266
267
268
269
270
271
# File 'lib/gitlab/json.rb', line 265

def stringify(jsonified)
  Gitlab::Json.dump(jsonified)
rescue EncodingError => ex
  # Raise the same error as the default implementation if we encounter
  # an error. These are usually related to invalid UTF-8 errors.
  raise JSON::GeneratorError, ex
end