Sha256: f68cd7868af983479a345bba64a740c725aedd683009fcd0024ff609d1a903c4

Contents?: true

Size: 1.22 KB

Versions: 3

Compression:

Stored size: 1.22 KB

Contents

require "json"

# Hack AwsLambda Ruby Runtime to fix .to_json issue collision with ActiveSupport.
# To reproduce:
#   Create a shared resource from the docs and call sns.publish
#
# Causes an infinite loop when calling sns.publish somehow.
# Overriding with JSON.dump and follow up with AWS ticket.
module AwsLambda
  class Marshaller
    class << self
      # By default, just runs #to_json on the method's response value.
      # This can be overwritten by users who know what they are doing.
      # The response is an array of response, content-type.
      # If returned without a content-type, it is assumed to be application/json
      # Finally, StringIO/IO is used to signal a response that shouldn't be
      # formatted as JSON, and should get a different content-type header.
      def marshall_response(method_response)
        case method_response
        when StringIO, IO
          [method_response, "application/unknown"]
        else
          # Note: Removed previous code which did force_encoding("ISO-8859-1").encode("UTF-8")
          # It caused issues with international characters.
          # It does not seem like we need the force_encoding anymore.
          JSON.dump(method_response)
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
jets-5.0.13 lib/jets/overrides/lambda/marshaller.rb
jets-5.0.12 lib/jets/overrides/lambda/marshaller.rb
jets-5.0.11 lib/jets/overrides/lambda/marshaller.rb