diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-11-04 00:09:24 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-11-04 00:09:24 +0300 |
commit | 9432ed811233643af1cb5ad78e2cd9755ed989a9 (patch) | |
tree | a6f4d254ebd818a58017b3bfb0911f4aae169fcf /lib/gitlab/json.rb | |
parent | 44434461b3c58336624125b5ab002e7200e4a208 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib/gitlab/json.rb')
-rw-r--r-- | lib/gitlab/json.rb | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/lib/gitlab/json.rb b/lib/gitlab/json.rb index 823d6202b1e..2c9b79bfc9d 100644 --- a/lib/gitlab/json.rb +++ b/lib/gitlab/json.rb @@ -41,6 +41,11 @@ module Gitlab # as the underlying implementation of this varies wildly based on # the adapter in use. # + # This method does, in some situations, differ in the data it returns + # compared to .generate. Counter-intuitively, this is closest in + # terms of response to JSON.generate and to the default ActiveSupport + # .to_json method. + # # @param object [Object] the object to convert to JSON # @return [String] def dump(object) @@ -263,5 +268,15 @@ module Gitlab buffer.string end end + + class RailsEncoder < ActiveSupport::JSON::Encoding::JSONGemEncoder + # 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 + def stringify(jsonified) + Gitlab::Json.dump(jsonified) + end + end end end |