Sha256: b9794fc8ec834e19414b255bc0e677f5ba552c9f7a3fde6babe08287b509bdbb

Contents?: true

Size: 512 Bytes

Versions: 19

Compression:

Stored size: 512 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

19 entries across 19 versions & 1 rubygems

Version Path
http-4.4.1 lib/http/mime_type/json.rb
http-4.4.0 lib/http/mime_type/json.rb
http-4.3.0 lib/http/mime_type/json.rb
http-4.2.0 lib/http/mime_type/json.rb
http-4.1.1 lib/http/mime_type/json.rb
http-4.1.0 lib/http/mime_type/json.rb
http-4.0.5 lib/http/mime_type/json.rb
http-4.0.4 lib/http/mime_type/json.rb
http-5.0.0.pre lib/http/mime_type/json.rb
http-4.0.3 lib/http/mime_type/json.rb
http-4.0.2 lib/http/mime_type/json.rb
http-4.0.1 lib/http/mime_type/json.rb
http-4.0.0 lib/http/mime_type/json.rb
http-3.3.0 lib/http/mime_type/json.rb
http-3.2.1 lib/http/mime_type/json.rb
http-3.2.0 lib/http/mime_type/json.rb
http-3.1.0 lib/http/mime_type/json.rb
http-3.0.0 lib/http/mime_type/json.rb
http-3.0.0.pre lib/http/mime_type/json.rb