Sha256: c2da7d1ce993c788d15efc8bbb1c1830ac57a17856f4a6cfef242a6965ba4ecd

Contents?: true

Size: 513 Bytes

Versions: 17

Compression:

Stored size: 513 Bytes

Contents

# frozen_string_literal: true

require "json"
require "http/mime_type/adapter"

module HTTP
  module MimeType
    # JSON encode/decode MIME type adapter
    class JSON < Adapter
      # Encodes object to JSON
      def encode(obj)
        return obj.to_json if obj.respond_to?(:to_json)

        ::JSON.dump obj
      end

      # Decodes JSON
      def decode(str)
        ::JSON.parse str
      end
    end

    register_adapter "application/json", JSON
    register_alias   "application/json", :json
  end
end

Version data entries

17 entries across 17 versions & 3 rubygems

Version Path
direct7-0.0.18 vendor/bundle/ruby/2.7.0/gems/http-5.1.1/lib/http/mime_type/json.rb
direct7-0.0.17 vendor/bundle/ruby/2.7.0/gems/http-5.1.1/lib/http/mime_type/json.rb
direct7-0.0.16 vendor/bundle/ruby/2.7.0/gems/http-5.1.1/lib/http/mime_type/json.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/http-5.2.0/lib/http/mime_type/json.rb
direct7-0.0.13 vendor/bundle/ruby/2.7.0/gems/http-5.1.1/lib/http/mime_type/json.rb
direct7-0.0.12 vendor/bundle/ruby/2.7.0/gems/http-5.1.1/lib/http/mime_type/json.rb
http-5.2.0 lib/http/mime_type/json.rb
direct7-0.0.11 vendor/bundle/ruby/2.7.0/gems/http-5.1.1/lib/http/mime_type/json.rb
http-5.1.1 lib/http/mime_type/json.rb
http-5.1.0 lib/http/mime_type/json.rb
http-5.0.4 lib/http/mime_type/json.rb
http-5.0.3 lib/http/mime_type/json.rb
http-5.0.2 lib/http/mime_type/json.rb
http-5.0.1 lib/http/mime_type/json.rb
http-5.0.0 lib/http/mime_type/json.rb
http-5.0.0.pre3 lib/http/mime_type/json.rb
http-5.0.0.pre2 lib/http/mime_type/json.rb